标签:des style blog http color java os io
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 606 Accepted Submission(s):
175
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<math.h> 5 #include<algorithm> 6 using namespace std; 7 const int N=40; 8 struct point 9 { 10 double x,y; 11 double angel; 12 int id; 13 } p[N],stack[N]; 14 int top,n; 15 16 double dis(point a,point b)//求距离 17 { 18 return sqrt ((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 19 } 20 21 bool mult(point p1,point p2,point p0)//叉乘 22 { 23 return (p1.x-p0.x)*(p2.y-p0.y) >= (p2.x-p0.x)*(p1.y-p0.y); 24 } 25 26 bool cmp(point a,point b) 27 { 28 if(a.angel == b.angel) 29 { 30 if (a.x == b.x) 31 return a.y > b.y; 32 return a.x > b.x; 33 } 34 return a.angel < b.angel; 35 } 36 37 void graham() 38 { 39 //p为点集,n为点的个数,stack为凸包点集,top为凸包个数 40 int i,k=0; 41 point temp; 42 for(i=0; i<n; i++) 43 if(p[i].y<p[k].y||((p[i].y==p[k].y)&&(p[i].x<p[k].x))) 44 k=i; 45 temp=p[0]; 46 p[0]=p[k]; 47 p[k]=temp; 48 for(i=1; i<n; i++) 49 p[i].angel=atan2(p[i].y-p[0].y,p[i].x-p[0].x); 50 sort(p+1,p+n,cmp); 51 stack[0]=p[0]; 52 stack[1]=p[1]; 53 stack[2]=p[2]; 54 top=3; 55 for(i=3; i<n; i++) 56 { 57 while(top > 2 && mult(stack[top-2],stack[top-1],p[i])<=0) 58 top--; 59 stack[top++]=p[i]; 60 } 61 } 62 int main() 63 { 64 int i,j,t,pp,q,cnt,ans; 65 int flag[500]; 66 scanf("%d",&t); 67 while(t--) 68 { 69 cnt=0; 70 scanf("%d%d%d",&pp,&q,&n); 71 for(i=0; i<n; i++) 72 { 73 scanf("%lf%lf",&p[i].x,&p[i].y); 74 p[i].id=i; 75 } 76 graham(); 77 memset(flag,0,sizeof(flag)); 78 for(i=0; i<top; i++) 79 { 80 flag[stack[i].id]=1; 81 } 82 flag[n]=flag[0]; 83 for(i=0; i<n; i++) 84 { 85 if(flag[i]==1&&flag[i+1]==0) 86 cnt++; 87 } 88 ans=q*(top-cnt)-pp*cnt; 89 if(ans<=0) 90 printf("0\n"); 91 else 92 printf("%d\n",ans); 93 } 94 return 0; 95 }
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/lxm940130740/p/3901251.html