织女的红线

织女的红线

Time Limit: 1000 ms Memory Limit: 65536 KiB

Submit Statistic

Problem Description

好久不见牛郎哥哥了,织女非常想他,但是她想考验一下牛郎在她不在的日子里有没有好好学习天天向上,于是乎
想出一个问题考一考他。织女找了一跟很细的红线和N颗相同的钉子,将各颗钉子钉在墙上作为一个多边
形的各个顶点,然后将红线缠在各个钉子上围成了多边形,多余的剪掉。下面给出了图示。
可惜牛郎不会算,悲剧了,但他不想让织女失望,还好有你这个朋友,你的任务是帮他计算出红线的长度。 

Input

在输入数据的第一行有两个数:N——钉子的数目(1 <= N <= 100),R——钉子的半径。所有的钉子半径
相同。接下来有N行数据,每行有两个空格隔开的实数代表钉子中心的坐标。坐标的绝对值不会超过
100。钉子的坐标从某一颗开始按照顺时针或逆时针的顺序给出。不同的钉子不会重合。

Output

输出一个实数(小数点后保留两位)————红线的长度。

Sample Input

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

Sample Output

14.28

Hint

Source

tongjiantao

// test.c++.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>

using namespace std;
const double P = 3.1415926;
class Coordinate
{
public:
	Coordinate();
	void get(double x,double y);
	double count(Coordinate a);
	~Coordinate();
	double x, y;
};
Coordinate::Coordinate()
{

}
Coordinate::~Coordinate()
{

}
void Coordinate::get(double x,double y)
{
	this->x = x;
	this->y = y;
}

double Coordinate::count(Coordinate p)
{
	return sqrt((x - p.x)*(x - p.x) + (y - p.y)*(y - p.y));
}

int main()
{
	int n, r;
	cin >> n >> r;
	Coordinate coor[101];
	for (int i = 0; i < n; i++)
	{
		double x, y;
		cin >> x >> y;
		coor[i].get(x, y);
	}
	double dist = 0.0;
	int j;
	for (j = 0; j < n - 1; j++)
	{
		dist += coor[j].count(coor[j + 1]);
	}
	dist += coor[j].count(coor[0]);
	cout << setiosflags(ios::fixed) << setprecision(2) << dist + 2 * P * r<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/feissss/article/details/82974513