现在的位置: 首页 > 综合 > 正文

ural 1020. Rope(几何)

2019年08月16日 ⁄ 综合 ⁄ 共 527字 ⁄ 字号 评论关闭

题目链接:ural 1020. Rope

题目大意:按照顺序给定N个点,每个点有半径R,问说用线环绕N个点所需要的长度。

解题思路:因为需要围成一个圈,所以旋转角度一定是一周,板径又都相同,所以直接就是两两点之间的距离加上一个周长。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;
const int maxn = 105;
const double pi = 4 * atan(1.0);

int N;
double R, x[maxn], y[maxn];

double dis (double x, double y) {
    return sqrt(x * x + y * y);
}

int main () {
    while (scanf("%d%lf", &N, &R) == 2) {
        for (int i = 0; i < N; i++)
            scanf("%lf%lf", &x[i], &y[i]);
        x[N] = x[0], y[N] = y[0];
        double ans = 2 * pi * R;
        for (int i = 0; i < N; i++)
            ans += dis(x[i]-x[i+1], y[i]-y[i+1]);
        printf("%.2lf\n", ans);
    }
    return 0;
}

抱歉!评论已关闭.