标签:bzoj1132 poi2008 tro 计算几何 叉积
#include <stdio.h>
int main()
{
puts("转载请注明出处[辗转山河弋流歌 by 空灰冰魂]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/46605807");
}
首先暴力是
可是三角形面积怎么求?一般我们都是用叉积……等等?那一个叉积不是被算了很多遍?
好了,正解出来了,先有序地把点排排序保证不重,然后算一下每个叉积的贡献,也就是每条边的贡献,,然后因为排序啥的,时间复杂度
然后这道题。呃,卡精度……?!
求叉积嘛,最后得到的东西都需要除以2,,先不除,到最后特判好了QwQ
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 3010
using namespace std;
struct Point
{
long long x,y;
void read(){scanf("%lld%lld",&x,&y);}
}now,p[N],tp[N];
inline long long xmul(Point B,Point C,Point A=now)
{return (C.y-A.y)*(B.x-A.x)-(B.y-A.y)*(C.x-A.x);}
bool cmpxy(Point A,Point B){return A.x==B.x?A.y<B.y:A.x<B.x;}
bool cmpmu(Point A,Point B){return xmul(A,B)>0;}
int n;
long long ans;
int main()
{
freopen("test.in","r",stdin);
int i,j,k;
long long sumx,sumy;
scanf("%d",&n);
for(i=1;i<=n;i++)p[i].read();
sort(p+1,p+n+1,cmpxy);
for(i=1;i<=n-2;i++)
{
now=p[i];
sumx=sumy=0;
for(j=i+1;j<=n;j++)tp[j]=p[j];
sort(tp+i+1,tp+n+1,cmpmu);
for(j=i+1;j<=n;j++)
{
sumx+=tp[j].x-now.x;
sumy+=tp[j].y-now.y;
}
for(j=i+1;j <n;j++)
{
sumx-=tp[j].x-now.x;
sumy-=tp[j].y-now.y;
ans+=(tp[j].x-now.x)*sumy;
ans-=(tp[j].y-now.y)*sumx;
}
}
if(ans&1)printf("%lld.5\n",ans>>1);
else printf("%lld.0\n",ans>>1);
return 0;
}
【BZOJ1132】【POI2008】Tro 计算几何 叉积求面积
标签:bzoj1132 poi2008 tro 计算几何 叉积
原文地址:http://blog.csdn.net/vmurder/article/details/46605807