POJ3348:Cows——题解
http://poj.org/problem?id=3348
题目大意:用已给出的点围出面积最大的凸包,输出面积/50(向下取整)
——————————————————————————
第一道凸包?以及不知道第几次的奶牛题……
显然裸题,切了。
(那博文的意义何在?)
(呃……方便以后抄板子?)
#include<cmath> #include<queue> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef double dl; const int N=1e5+5; inline int read(){ int X=0,w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } struct Point{ dl x,y; Point(dl x0=0,dl y0=0){x=x0,y=y0;} }; dl dis(Point a,Point b){//求两点距离 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); } typedef Point Vector; Vector operator +(Point a,Point b){return Vector(a.x+b.x,a.y+b.y);} Vector operator -(Point a,Point b){return Vector(a.x-b.x,a.y-b.y);} Vector operator *(Point a,dl k){return Vector(a.x*k,a.y*k);} Vector operator /(Point a,dl k){return Vector(a.x/k,a.y/k);} dl Dot(Vector a,Vector b){//求点积 return a.x*b.x+a.y*b.y; } dl Cross(Vector a,Vector b){//求叉积 return a.x*b.y-b.x*a.y; } dl Cross(Point sp,Point ep,Point op){//得到sp-op和ep-op的叉积 return (sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y); } Point p[N],q[N]; int n,k,m; inline bool cmp(int u,int v){ int det=Cross(p[u],p[v],p[1]); if(det!=0)return det>0; return dis(p[1],p[u])<dis(p[1],p[v]); } void graham(){ int id=1; for(int i=2;i<=n;i++) if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y)) id=i; if(id!=1)swap(p[1],p[id]); static int per[N]; for(int i=1;i<=n;i++)per[i]=i; sort(per+2,per+n+1,cmp); q[++m]=p[1]; for(int i=2;i<=n;i++){ int j=per[i]; while(m>=2&&Cross(p[j],q[m],q[m-1])>=0)m--; q[++m]=p[j]; } return; } inline int area(){ int ans=0; q[0].x=0;q[0].y=0; for(int i=1;i<=m;i++)ans+=Cross(q[i],q[i%m+1],q[0]); return abs(ans)/2; } int main(){ n=read(); for(int i=1;i<=n;i++)p[i].x=read(),p[i].y=read(); graham(); int ans=area()/50; printf("%d\n",ans); return 0; }