2544: Length of Rope

本文介绍了一个经典的几何问题——如何计算一根绳子的长度,该绳子围绕着一个凸多边形的所有顶点(被视为半径为R的钉子),并紧密贴合这些钉子。文章给出了输入数据格式,包括顶点数量、钉子半径及位置,并提供了输出要求及示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 2544: Length of Rope


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
1s32768K17458Standard

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.

Problem illustration

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值