POJ1113 Wall
Description
Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Your task is to help poor Architect to save his head, by writing a program that will find the minimum possible length of the wall that he could build around the castle to satisfy King's requirements.
The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.
Input
The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.
Output
Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.
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
题目大意就是求一个凸包周长,然后再加一个以l为半径的圆的周长。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<algorithm> 7 #include<cmath> 8 #define maxn 1005 9 #define mod 1000000009 10 #define ll long long 11 using namespace std; 12 double sqr(double a){ 13 return a*a; 14 } 15 struct point{ 16 double x,y; 17 inline point operator -(point t){ 18 point ret; 19 ret.x=x-t.x; 20 ret.y=y-t.y; 21 return ret; 22 } 23 inline point operator +(point t){ 24 point ret; 25 ret.x=x+t.x; 26 ret.y=y+t.y; 27 return ret; 28 } 29 inline int det(point t){ 30 return x*t.y-t.x*y; 31 } 32 inline double dis(point t){ 33 return sqrt(sqr(x-t.x)+sqr(y-t.y)); 34 } 35 }d[maxn]; 36 bool cmp(point a,point b){ 37 if(a.x!=b.x)return a.x<b.x; 38 else return a.y<b.y; 39 } 40 int con[maxn],c,n,l; 41 int main(){ 42 scanf("%d%d",&n,&l); 43 for(int i=1;i<=n;i++) 44 scanf("%lf%lf",&d[i].x,&d[i].y); 45 sort(d+1,d+1+n,cmp); 46 int tot=0,tmp; 47 for(int i=1;i<=n;i++){ 48 while((tot>1)&&((d[con[tot-1]]-d[con[tot-2]]).det(d[i]-d[con[tot-1]])<=0)) 49 tot--; 50 con[tot++]=i; 51 } 52 tmp=tot; 53 for(int i=n-1;i>0;i--){ 54 while((tot>tmp)&&((d[con[tot-1]]-d[con[tot-2]]).det(d[i]-d[con[tot-1]])<=0)) 55 tot--; 56 con[tot++]=i; 57 } 58 c=tot; 59 double ans=0; 60 for(int i=0;i<c-1;i++) 61 ans+=d[con[i]].dis(d[con[i+1]]); 62 ans+=d[con[0]].dis(d[con[c-1]]); 63 ans+=3.1415926*2*l; 64 printf("%.0lf\n",ans); 65 return 0; 66 }