Description
There are n circles in a plane with equal radius. Now we wanna draw ashortest enclosed curve, and every circles lie in this curve. You have to writea program to calculate the length of this curve.
Input Description
The input contains multiple testcases.
For each case, the first line contains two integer n and r (1 ≤ n≤ 10000) denoting the number of circles and the radius of them. After that there aren lines, each line contains two integers denoting the coordinate of each circle.The absolute value of then would not be greater then 10000, and the radius is no large than 10000.
For each case, the first line contains two integer n and r (1 ≤ n≤ 10000) denoting the number of circles and the radius of them. After that there aren lines, each line contains two integers denoting the coordinate of each circle.The absolute value of then would not be greater then 10000, and the radius is no large than 10000.
Output Description
For each case output one real number (round to 0.01) which is the length of that curve.
Sample Input
2 1 -1 0 1 0 5 1 1 0 0 1 -1 0 0 -1 0 0
Sample Output
10.28 11.94
真心无语了。。选拔赛的时候我带的模板中还有这道题呢。。我卡在那树深度的那道题。唉唉唉#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; #define pi acos(-1.0); struct Point { int x,y; }point[50008],res[50008]; bool cmp(Point a,Point b) { if(a.x<b.x)return 1; if(a.x>b.x)return 0; if(a.x==b.x)return a.y>b.y?0:1; } bool ral(Point p1,Point p2,Point p3) { if((p3.y-p1.y)*(p2.x-p1.x)>(p3.x-p1.x)*(p2.y-p1.y))return 1; return 0; } double qlen(Point a,Point b) { return sqrt(double((b.y-a.y)*(b.y-a.y)+(b.x-a.x)*(b.x-a.x))); } int main() { int n,r; while(scanf("%d%d",&n,&r)==2) { for(int i=0;i<n;i++) { scanf("%d%d",&point[i].x,&point[i].y); } sort(point,point+n,cmp); int m=-1; for(int i=0;i<n;i++) { while(m>=1&&!ral(res[m-1],res[m],point[i])) { m--; } res[++m]=point[i]; } int k=m; for(int i=n-2;i>=0;i--) { while(k>m&&!ral(res[k-1],res[k],point[i])) { k--; } res[++k]=point[i]; } double sum=0; sum=2*r*pi; for(int i=0;i<k;i++) { sum+=qlen(res[i],res[i+1]); } printf("%.2lf\n",sum);//这里不能用llf } return 0; }