背景 Background
平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。
现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。
描述 Description
求出绳子的长度
输入格式 Input Format
第1行两个数:整数N(1<=N<=100)和实数R。
接下来N行按逆时针顺序给出N个钉子中心的坐标
坐标的绝对值不超过100。
输出格式 Output Format
一个数,绳子的长度,精确到小数点后2位。
题目需要细心一点即可,大钉子周长加凸多边形的周长。
/* *
* Description: Calculate the circumference of the convex polygon.(come from Vijos1007)
* Author: Gecko
* Date: 2012-12-03
* Note:
* */
#include <stdio.h>
#include <math.h>
int main()
{
double Circum,R,x0,y0,x1,y1,x,y;
int n,i;
scanf("%d %lf",&n,&R);
scanf("%lf %lf",&x0,&y0);
x1 = x0;
y1 = y0;
for(i=1;i<n;i++)
{
scanf("%lf %lf",&x,&y);
Circum += sqrt(pow((x-x1),2)+pow((y-y1),2));
x1 = x;
y1 = y;
}
Circum += sqrt(fabs(x0-x1)+fabs(y0-y1));
Circum += 3.141592653*2*R;
printf("%.2lf",Circum);
return 0;
}