3575 - 绕钉子的长绳

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。

现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。

pi=3.14159265

描述

求出绳子的长度

题目输入

第1行两个数:整数N(1<=N<=100)和实数R。

接下来N行按逆时针顺序给出N个钉子中心的坐标

坐标的绝对值不超过100。

题目输出

一个数,绳子的长度,精确到小数点后2位。

输入/输出样例

输入格式

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

输出格式

14.28

C++解答

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#define pi 3.1415926539
using namespace std;
float juli(int,int);
float a[110][4];
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int n;
	float s=0.0;
	float r;
	scanf("%d%f",&n,&r);
	for(int i=1;i<=n;i++)
		scanf("%f%f",&a[i][1],&a[i][2]);
    int z=1;
	while(1)
	{
         if(z==n)
	    {
            s+=juli(n,1);
            break;
		}
	    s+=juli(z,z+1);
	    z++;

    }
	s+=2*pi*r;
	printf("%.2f",s);
	//system("pause");
}
float juli(int c,int d)
{
	float s;
    s=sqrt(pow(a[c][1]-a[d][1],2)+pow(a[c][2]-a[d][2],2));
	return s;
}