bzoj1132:[POI2008]Tro
传送门
自己的计算几何还是挺渣的呢。
其实只要考虑一下叉积的式子就可以想到前缀和了,但是显然需要按照极角序来做才能去掉绝对值
代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
void read(int &x) {
char ch; bool ok;
for(ok=0,ch=getchar(); !isdigit(ch); ch=getchar()) if(ch=='-') ok=1;
for(x=0; isdigit(ch); x=x*10+ch-'0',ch=getchar()); if(ok) x=-x;
}
#define rg register
const int maxn=3010;
int n;long long ans,sumx[maxn],sumy[maxn];
struct oo{int x,y;}a[maxn],b[maxn];
bool cmp(oo a,oo b){return a.x==b.x?a.y<b.y:a.x<b.x;}
oo operator-(oo a,oo b){return (oo){a.x-b.x,a.y-b.y};}
bool Cmp(oo a,oo b){return 1ll*a.x*b.y>1ll*a.y*b.x;}
int main()
{
read(n);
for(rg int i=1;i<=n;i++)read(a[i].x),read(a[i].y);
sort(a+1,a+n+1,cmp);
for(rg int i=1;i<=n;i++)
{
for(rg int j=i+1;j<=n;j++)b[j]=a[j]-a[i];
sort(b+i+1,b+n+1,Cmp);
for(rg int j=n;j>i;j--)
ans+=b[j].x*sumy[j+1]-b[j].y*sumx[j+1],
sumx[j]=sumx[j+1]+b[j].x,sumy[j]=sumy[j+1]+b[j].y;
}
printf("%lld.%lld\n",ans/2,ans%2*5);
}