标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 32808 | Accepted: 11137 |
Description
Input
Output
Sample Input
9 100 200 400 300 400 300 300 400 300 400 400 500 400 500 200 350 200 200 200
Sample Output
1628
Hint
Source
1 /************************************************************************* 2 > File Name: code/poj/1113.cpp 3 > Author: 111qqz 4 > Email: rkz2013@126.com 5 > Created Time: 2015年11月09日 星期一 16时33分28秒 6 ************************************************************************/ 7 8 #include<iostream> 9 #include<iomanip> 10 #include<cstdio> 11 #include<algorithm> 12 #include<cmath> 13 #include<cstring> 14 #include<string> 15 #include<map> 16 #include<set> 17 #include<queue> 18 #include<vector> 19 #include<stack> 20 #include<cctype> 21 #define fst first 22 #define sec second 23 #define lson l,m,rt<<1 24 #define rson m+1,r,rt<<1|1 25 #define ms(a,x) memset(a,x,sizeof(a)) 26 using namespace std; 27 const double eps = 1E-8; 28 const int dx4[4]={1,0,0,-1}; 29 const int dy4[4]={0,-1,1,0}; 30 typedef long long LL; 31 const int inf = 0x3f3f3f3f; 32 const double pi = acos(-1.0); 33 const int N=1E3+7; 34 int n,l; 35 int top; 36 int dblcmp(int d) 37 { 38 return d<-eps?-1:d>eps; 39 } 40 struct point 41 { 42 double x,y; 43 point (){} 44 point (double _x,double _y): 45 x(_x),y(_y){}; 46 47 void input() 48 { 49 scanf("%lf %lf",&x,&y); 50 } 51 point operator - (const point &p) const{ 52 return point (x-p.x,y-p.y); 53 } 54 double operator ^ (const point &p) const{ 55 return x*p.y-y*p.x; 56 } 57 bool operator < (const point a)const{ 58 return dblcmp(a.x-x)==0?dblcmp(y-a.y)<0:x<a.x; 59 } 60 double distance(point p) 61 { 62 return hypot(x-p.x,y-p.y); 63 } 64 point sub(point p) 65 { 66 return point(x-p.x,y-p.y); 67 } 68 69 double det(point p) 70 { 71 return x*p.y-y*p.x; 72 } 73 74 75 }p[N]; 76 77 78 struct polygon 79 { 80 point p[N]; 81 int n; 82 void input() 83 { 84 85 p[0].input(); 86 for ( int i = 1 ; i < n ; i++) 87 { 88 p[i].input(); 89 if (p[i].y>p[0].y||(p[i].y==p[0].y&&p[i].x>p[0].x)) 90 swap(p[0],p[i]); 91 } 92 } 93 94 struct cmp 95 { 96 point p; 97 cmp(const point &p0){p=p0;} 98 bool operator()(const point &aa,point &bb) 99 { 100 point a=aa,b=bb; 101 int d = dblcmp((a-p)^(b-p)); 102 if (d==0) 103 { 104 return dblcmp(a.distance(p)-b.distance(p))<0; 105 } 106 else 107 return d>0; 108 } 109 110 }; 111 112 void getconvex(polygon &convex,int &top) 113 { 114 int i,j,k; 115 sort(p,p+n); //极角排序 116 convex.n=n; 117 118 for ( int i = 0 ; i < min (n,2);i++) 119 { 120 convex.p[i] = p[i]; 121 } 122 if (n<=2) return ; 123 top = convex.n; 124 top = 1; 125 for ( int i = 2 ; i < n ; i++) 126 { 127 while (top&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0) top--; 128 129 convex.p[++top]=p[i]; 130 } 131 132 int tmp = top; 133 convex.p[++top] = p[n-2]; 134 for (int i = n-3 ; i >= 0 ; i--) 135 { 136 while (top!=tmp&&convex.p[top].sub(p[i]).det(convex.p[top-1].sub(p[i]))<=0) 137 top--; 138 convex.p[++top]=p[i]; 139 } 140 // ztop = top; 141 142 }; 143 144 }pol; 145 146 int main() 147 { 148 #ifndef ONLINE_JUDGE 149 freopen("in.txt","r",stdin); 150 #endif 151 152 while (scanf("%d %d",&n,&l)!=EOF) 153 { 154 pol.n=n; 155 pol.input(); 156 polygon conv; 157 pol.getconvex(conv,top); 158 159 double res=0; 160 // cout<<"top:"<<top<<endl; 161 for ( int i = 0 ; i < top ; i++) 162 res +=conv.p[i].distance(conv.p[i+1]); 163 res +=conv.p[0].distance(conv.p[top]); 164 165 res = res + 2*pi*l; 166 printf("%d\n",(int)(res+0.5)); 167 168 169 170 } 171 172 173 #ifndef ONLINE_JUDGE 174 #endif 175 fclose(stdin); 176 return 0; 177 }
标签:
原文地址:http://www.cnblogs.com/111qqz/p/4952325.html