poj解题报告——poj 2365 Rope

原题入口

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  100
double 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AlbertS

常来“玩”啊~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值