2544: Length of Rope
| Result | TIME Limit | MEMORY Limit | Run Times | AC Times | JUDGE |
|---|---|---|---|---|---|
| 1s | 32768K | 174 | 58 | Standard |
There is a convex polygon whose vertices are all nails. The nails are of radius R. We need a rope to round these nails tightly. You can see an example here.
Input
The input contains several cases. Each case start with an integer N and a real number R. N is the number of vertices of the polygon. R is the radius of nails. 1<=N<=200. Each of the next N lines is two real numbers, standing for the position of the corresponding nail. The nails are listed clockwise or counterclockwise.
Output
The length of the rope with two digits precision (after a decimal point). Each answer takes a line.
Sample Input
4 1 0.0 0.0 2.0 0.0 2.0 2.0 0.0 2.0
Sample Output
14.28
Problem Source: liuctic
#include<stdio.h>
#include<math.h>
double dis(double x1,double y1,double x2,double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
const double pi=3.1415926;
int main()
{
double x[210],y[210];
double r;
int n,i;
while(scanf("%d%lf",&n,&r)==2)
{
double l=pi*r*2;
//printf("%.2lf/n",l);
scanf("%lf%lf",&x[1],&y[1]);
for(i=2;i<=n;i++)
{
scanf("%lf%lf",&x[i],&y[i]);
l+=dis(x[i-1],y[i-1],x[i],y[i]);
//printf("%.2lf/n",l);
}
//scanf("%lf%lf",&x[n],&y[n]);
l+=dis(x[1],y[1],x[n],y[n]);
printf("%.2lf/n",l);
}
return 0;
}
本文介绍了一个经典的几何问题——如何计算一根绳子的长度,该绳子围绕着一个凸多边形的所有顶点(被视为半径为R的钉子),并紧密贴合这些钉子。文章给出了输入数据格式,包括顶点数量、钉子半径及位置,并提供了输出要求及示例。

被折叠的 条评论
为什么被折叠?



