3 0 0 3 1 1 2 2 2 1 0
Case #1: 100
//109MS 292K #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; struct Point { int x,y,k,id,vis,flag; Point(int x=0,int y=0):x(x),y(y) {} //构造函数 }; typedef Point Vector; Point operator-(Point A,Point B) { return Point(A.x-B.x,A.y-B.y); } int Cross(Point A,Point B) { return A.x*B.y-A.y*B.x; } int cmp1(Point a,Point b) { if(a.k==b.k) { if(a.x==b.x)return a.y<b.y; return a.x<b.x; } return a.k>b.k; } int cmp2(Point a,Point b) { return a.id<b.id; } int ConvexHull(Point* p,int n,Point* ch)//求凸包 { int m=0; for(int i=0;i<n;i++) { while(m>1&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; ch[m++]=p[i]; } int k=m; for(int i=n-2;i>=0;i--) { while(m>k&&Cross(ch[m-1]-ch[m-2],p[i]-ch[m-2])<=0)m--; ch[m++]=p[i]; } if(n>1)m--; return m; } int main() { int n,cas=1; while(scanf("%d",&n),n) { Point P[507],ch[507],v[507]; int i; for(i=0; i<n; i++) { scanf("%d%d%d",&P[i].x,&P[i].y,&P[i].k); P[i].id=i;P[i].vis=P[i].flag=0; } sort(P,P+n,cmp1); v[0]=P[0]; for(i=1;i<n;i++) if(P[i].k!=P[i-1].k)break; else { v[i]=P[i]; if(P[i].x==P[i-1].x&&P[i].y==P[i-1].y)P[i].vis=v[i].vis=P[i-1].vis=v[i-1].vis=1; } int num=i; int m=ConvexHull(v,num,ch); if(P[0].k==0)num=0; for(i=0;i<num;i++) for(int j=0;j<m;j++) if(Cross(ch[j]-ch[(j+1)%m],ch[j]-P[i])==0) { if(!P[i].vis)P[i].flag=1; break; } sort(P,P+n,cmp2); printf("Case #%d: ",cas++); for(int i=0;i<n;i++) printf("%d",P[i].flag); printf("\n"); } return 0; }
HDU 4946 Area of Mushroom 求凸包边上的点,布布扣,bubuko.com
HDU 4946 Area of Mushroom 求凸包边上的点
原文:http://blog.csdn.net/crescent__moon/article/details/38584803