1007

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


 

發佈了46 篇原創文章 · 獲贊 102 · 訪問量 47萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章