标签:end logs stream zha src using opera out shang
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 #include<vector> 6 #include<cmath> 7 #define dd double 8 using namespace std; 9 const int N=10006; 10 const dd tiny=0.0000001; 11 12 struct son 13 { 14 dd x,y; 15 friend bool operator < (son a,son b){return a.x<b.x;} 16 friend son operator - (son a,son b){return (son){a.x-b.x,a.y-b.y};} 17 }ji[N]; 18 int n,he; 19 son zhan[N*5]; 20 vector<son> q; 21 22 dd chacheng(son a,son b) 23 { 24 return a.x*b.y-b.x*a.y; 25 } 26 27 int check(son a,son b,son c) 28 { 29 return chacheng(b-a,c-b)>tiny; 30 } 31 32 void xiatubao() 33 { 34 he=0;zhan[++he]=ji[1];zhan[++he]=ji[2]; 35 for(int i=3;i<=n;++i) 36 { 37 while(he>=2&&!check(zhan[he-1],zhan[he],ji[i]))--he; 38 zhan[++he]=ji[i]; 39 } 40 for(int i=1;i<=he;++i) 41 q.push_back(zhan[i]); 42 } 43 44 void shangtubao() 45 { 46 he=0;zhan[++he]=ji[n];zhan[++he]=ji[n-1]; 47 for(int i=n-2;i>=1;--i) 48 { 49 while(he>=2&&!check(zhan[he-1],zhan[he],ji[i]))--he; 50 zhan[++he]=ji[i]; 51 } 52 for(int i=1;i<=he;++i) 53 q.push_back(zhan[i]); 54 } 55 void out11(); 56 void Graham() 57 { 58 xiatubao(); 59 //out11(); 60 shangtubao(); 61 //out11(); 62 } 63 64 dd jisuan() 65 { 66 dd ans=0; 67 for(int i=0,s=q.size()-1;i<s;++i) 68 ans+=sqrt( (q[i].x-q[i+1].x)*(q[i].x-q[i+1].x)+(q[i].y-q[i+1].y)*(q[i].y-q[i+1].y) ); 69 return ans; 70 } 71 72 void out11() 73 { 74 printf("\n"); 75 for(int i=1;i<=n;++i) 76 printf("%.2lf %.2lf\n",ji[i].x,ji[i].y); 77 printf("\n"); 78 printf("\n"); 79 for(int i=0,s=q.size();i<s;++i) 80 printf("%.2lf %.2lf\n",q[i].x,q[i].y); 81 printf("\n"); 82 } 83 84 int main(){ 85 freopen("fc.in","r",stdin); 86 freopen("fc.out","w",stdout); 87 scanf("%d",&n); 88 for(int i=1;i<=n;++i) 89 scanf("%lf%lf",&ji[i].x,&ji[i].y); 90 sort(ji+1,ji+1+n); 91 Graham(); 92 printf("%.2lf",jisuan()); 93 //while(1); 94 return 0; 95 }
标签:end logs stream zha src using opera out shang
原文地址:http://www.cnblogs.com/A-LEAF/p/7290864.html