POJ 上的一套水题,哈哈~~~,最后一题很恶心,不想写了~~~

 

Rope
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7410   Accepted: 2603

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. 
Ural State University Internal Contest October'2000 Junior Session 
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

 
题意:逆时针给定N个圆的圆心坐标,和半径,求外面的绳子的总长度。
猜测了一下,弧的周长,恰好是一个圆周。
有大佬用凸包,我不怎么会计算几何~~~
#include <bits/stdc++.h>

using namespace std;

#define PI acos(-1)

const int maxn = 105;

struct Node {
    double x,y;
}nodes[maxn];

double dist (int i,int j) {
    double tx = nodes[i].x - nodes[j].x;
    double ty = nodes[i].y - nodes[j].y;
    return sqrt(tx*tx+ty*ty);
}

int main()
{
    int n;
    double r;
    scanf("%d%lf",&n,&r);

    for(int i = 0; i < n; i++) {
        scanf("%lf%lf",&nodes[i].x,&nodes[i].y);
    }

    double ans =  0;

    for(int i = 0; i < n; i++) {
        ans+= dist(i,(i+1)%n);
    }

    ans+= PI*2*r;
    printf("%.2f\n",ans);


    return 0;
}
View Code

 

相关文章:

  • 2021-12-09
  • 2021-06-01
  • 2021-10-03
  • 2022-03-03
  • 2021-08-07
  • 2021-11-26
  • 2021-06-07
  • 2021-09-14
猜你喜欢
  • 2021-07-23
  • 2022-12-23
  • 2022-03-08
  • 2022-01-28
  • 2021-07-11
  • 2021-09-28
  • 2021-08-02
相关资源
相似解决方案