poj 1113 Wall
凸包周长+圆周长
View Code
1 /* 2 Coder:Zhaofa Fang 3 Lang:C++ 4 */ 5 #include <cstdio> 6 #include <cstdlib> 7 #include <iostream> 8 #include <cmath> 9 #include <cstring> 10 #include <algorithm> 11 #include <string> 12 #include <vector> 13 #include <queue> 14 #include <stack> 15 #include <map> 16 #include <set> 17 #define pb push_back 18 using namespace std; 19 20 //========================================== 21 const double PI=acos(-1); 22 23 struct Point 24 { 25 double x,y; 26 }point[1005],res[1005]; 27 28 double det(double x1,double y1,double x2,double y2) 29 { 30 return x1*y2-x2*y1; 31 } 32 double xmult(Point o,Point a ,Point b) 33 { 34 return det(a.x-o.x,a.y-o.y,b.x-o.x,b.y-o.y); 35 } 36 double dis(Point a,Point b) 37 { 38 return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 39 } 40 bool cmp(const Point &x,const Point &y) 41 { 42 if(xmult(point[0],x,y)==0) 43 return dis(point[0],x)<dis(point[0],y); 44 return xmult(point[0],x,y)>0; 45 } 46 double Graham(int n) 47 { 48 Point tmp; 49 int k=0,top=2; 50 for(int i=1;i<n;i++) 51 { 52 if(point[i].y<point[k].y || point[i].y==point[k].y && point[i].x<point[k].x) 53 k=i; 54 } 55 tmp=point[0],point[0]=point[k],point[k]=tmp; 56 sort(point+1,point+n,cmp); 57 res[0]=point[0],res[1]=point[1],res[2]=point[2]; 58 for(int i=3;i<n;i++) 59 { 60 while(top && xmult(res[top-1],res[top],point[i])<=0)top--; 61 res[++top]=point[i]; 62 } 63 double sum=0; 64 for(int i=1;i<top+1;i++) 65 { 66 sum += dis(res[i],res[i-1]); 67 } 68 sum += dis(res[top],res[0]); 69 return sum; 70 } 71 int main() 72 { 73 int n; 74 double L; 75 while(~scanf("%d%lf",&n,&L)) 76 { 77 for(int i=0;i<n;i++) 78 { 79 scanf("%lf%lf",&point[i].x,&point[i].y); 80 } 81 double sum=Graham(n); 82 sum+=2*PI*L; 83 printf("%.0f\n",sum); 84 } 85 return 0; 86 }
by Farmer