标签:des style blog http java color os strong
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3229 Accepted Submission(s): 919
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <math.h> 5 #include <stdlib.h> 6 #include <algorithm> 7 8 using namespace std; 9 10 const int MAX=1005; 11 const double eps=1e-6; 12 13 typedef struct point 14 { 15 double x,y; 16 }point; 17 18 point c[MAX]; 19 int top; 20 21 bool dy(double x,double y) 22 { 23 return x>y+eps; 24 } 25 bool xy(double x,double y) 26 { 27 return x<y-eps; 28 } 29 bool xyd(double x,double y) 30 { 31 return x<y+eps; 32 } 33 bool dyd(double x,double y) 34 { 35 return x>y-eps; 36 } 37 bool dd(double x,double y) 38 { 39 return fabs(x-y)<eps; 40 } 41 42 double crossProduct(point a,point b,point c) 43 { 44 return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); 45 } 46 double dist(point a,point b) 47 { 48 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 49 } 50 51 bool cmp(point a,point b) 52 { 53 if(dd(a.y,b.y)) 54 { 55 return xy(a.x,b.x); 56 } 57 return xy(a.y,b.y); 58 } 59 bool cmp1(point a,point b) 60 { 61 double len=crossProduct(c[0],a,b); 62 if(dd(len,0.0)) 63 { 64 return xy(dist(c[0],a),dist(c[0],b)); 65 } 66 return xy(len,0.0); 67 } 68 69 point stk[MAX]; 70 71 double dis() 72 { 73 double sum=0.0; 74 for(int i=0;i<top;i++) 75 { 76 sum+=dist(stk[i],stk[i+1]); 77 } 78 sum+=dist(stk[top],stk[0]); 79 return sum; 80 } 81 82 double Graham(int n) 83 { 84 sort(c,c+n,cmp); 85 sort(c+1,c+n,cmp1); 86 top=0; 87 stk[top++]=c[0]; 88 stk[top++]=c[1]; 89 stk[top++]=c[2]; 90 top--; 91 for(int i=3;i<n;i++) 92 { 93 while(1) 94 { 95 point a,b; 96 a=stk[top]; 97 b=stk[top-1]; 98 if(xyd(crossProduct(a,b,c[i]),0.0)) 99 { 100 top--; 101 } 102 else 103 break; 104 } 105 stk[++top]=c[i]; 106 } 107 return dis(); 108 } 109 110 int main() 111 { 112 int i,j,k,t; 113 int n,m; 114 int cas=0; 115 scanf("%d",&t); 116 while(t--) 117 { 118 scanf("%d%d",&n,&m); 119 for(i=0;i<n;i++) 120 { 121 scanf("%lf%lf",&c[i].x,&c[i].y); 122 } 123 if(cas++) 124 { 125 printf("\n"); 126 } 127 double re=4*acos(0.0)*m; 128 double sum=Graham(n); 129 printf("%.0lf\n",sum+re); 130 } 131 }
hdu 1348 (凸包求周长),布布扣,bubuko.com
标签:des style blog http java color os strong
原文地址:http://www.cnblogs.com/ccccnzb/p/3868579.html