poj解题报告——poj 2365 Rope

来源:互联网 发布:有声单词软件下载 编辑:程序博客网 时间:2024/06/06 23:16

原题入口

poj 2365 Rope

题目描述

Rope
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7372 Accepted: 2587

Description
Plotters have barberically hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.

Your task is to find out a length of the rope.

Input
There two numbers in the first line of the standard input: N — a number of nails (1 <= N <= 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn’t exceed 100. The nails are described in a clockwise order starting from an arbitrary nail. Heads of different nails don’t adjoin.

Output
The standard output should contain in its only line a real number with two digits precision (after a decimal point) — a length of the rope.

Sample Input

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0

Sample Output

14.28

Source
Ural State University Internal Contest October’2000 Junior Session

解题代码

#include <iostream>#include <iomanip>#include <cmath>using namespace std;#define PI  3.141592653#define NAIL_COUNT  100double arNailPos[NAIL_COUNT][NAIL_COUNT] = {0};double GetLenByPos(double x1, double y1, double x2, double y2){    return sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));}int main(){    int N;                  // 钉子数    double dR;              // 钉子半径    double dRopeLength = 0; // 绳子长度    cin >> N >> dR;    cin >> arNailPos[0][0] >> arNailPos[0][1];    for (int nIndex = 1; nIndex < N; ++nIndex)    {        cin >> arNailPos[nIndex][0] >> arNailPos[nIndex][1];        dRopeLength += GetLenByPos(arNailPos[nIndex - 1][0], arNailPos[nIndex - 1][1], arNailPos[nIndex][0], arNailPos[nIndex][1]);    }    dRopeLength += GetLenByPos(arNailPos[N - 1][0], arNailPos[N - 1][1], arNailPos[0][0], arNailPos[0][1]);    dRopeLength += 2 * PI * dR;    cout.setf(ios::fixed);      cout << fixed << setprecision(2) << dRopeLength << endl; // 输出绳子长度保留2位小数,不足两位填充0    return 0;}

解题过程

  • 题意:在一个平面上钉N个钉子,每个钉子有一个半径R,求这N个钉子构成的凸多边形周长是多少

  • 思路:将N个钉子构成的线段依次加起来就行,注意加上钉子上缠绕绳子的长度,其实就是一个钉子的周长

提交结果

poj2365

0 0
原创粉丝点击