【BZOJ】【P1132】【POI2008】【Tro】【题解】【极角序去绝对值】

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1132

三角形求面积哪家强?

中国山东找叉积

S△=|x1y2-x2y1|/2

想办法去掉绝对值

从左下到右上枚举点作原点

再搞一个极角序

计算原点右上方每两个点与原点形成的S

线性计算,啊,会吧

Code:

#include<bits/stdc++.h>
using namespace std;
const int maxn=3005;
typedef long long LL;
struct Point{
	LL x,y;
	Point(LL _x=0,LL _y=0):
		x(_x),y(_y){}
}O,p[maxn],o[maxn];
Point operator-(Point a,Point b){return Point(a.x-b.x,a.y-b.y);}
LL Cross(Point a,Point b){a=a-O;b=b-O;return a.x*b.y-a.y*b.x;}
bool cmp1(Point a,Point b){return a.x<b.x||(a.x==b.x&&a.y<b.y);}
bool cmp2(Point a,Point b){return Cross(a,b)>0;}
int n;LL ans=0;
LL getint(){
	LL res=0;char c=getchar();
	while(!isdigit(c))c=getchar();
	while(isdigit(c))res=(res<<1)+(res<<3)+c-'0',c=getchar();
	return res;
}
int main(){
	n=getint();
	for(int i=1;i<=n;i++)p[i].x=getint(),p[i].y=getint();
	sort(p+1,p+1+n,cmp1);
	for(int i=1;i<=n-2;i++){
		O=p[i];
		LL dx=0,dy=0;
		for(int j=i+1;j<=n;j++)o[j]=p[j];
		sort(o+i+1,o+1+n,cmp2);
		for(int j=i+1;j<=n;j++)
			dx+=o[j].x-O.x,dy+=o[j].y-O.y;
		for(int j=i+1;j<n;j++){
			dx-=o[j].x-O.x,dy-=o[j].y-O.y;
			ans+=(o[j].x-O.x)*dy-(o[j].y-O.y)*dx;
		}
	}if(ans&1)printf("%lld.5\n",ans/2);
	else printf("%lld.0\n",ans/2);
	return 0;
}


你可能感兴趣的:(bzoj)