您的位置:首页 > 运维架构

ural 1020. Rope(几何)

2014-10-24 00:08 302 查看
题目链接: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
= x[0], y
= 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: