码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2365【YY水题】

时间:2018-07-31 01:40:10      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:col   different   div   contain   根据   include   into   小数点   0ms   

题目链接:POJ 2365 Rope

Rope

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7488   Accepted: 2624

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

 

题目大意:

有N颗钉子,每颗钉子半径为R,用一条细线把他们围起来,求细线长度。

大概思路:

①根据每个点的坐标求出两个钉子中心点的距离

②除了中心点的距离,还要加上一颗钉子的周长,一开始我还在想怎么算线接触钉子所占的弧长,其实整体来看,每颗钉子半径相同,细线要围一圈,角度之和为360度,所以加上一个圆周就搞定了!

③半径R要用double, 圆周率要精确到小数点后三位(32ms)小数点后四位(0ms)

 

AC code(160k 0ms):

 1 #include <cmath>
 2 #include <cstdio>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define INF 0x3f3f3f3f
 6 #define pi 3.1415
 7 using namespace std;
 8 
 9 const int MAXN = 101;
10 
11 double x[MAXN], y[MAXN];
12 double ans, R;
13 int N;
14 
15 double s(double x1, double x2, double y1, double y2)
16 {
17     return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
18 }
19 
20 int main()
21 {
22     scanf("%d%lf", &N, &R);
23     for(int i = 1; i <= N; i++)
24     {
25         scanf("%lf %lf", &x[i], &y[i]);
26     }
27     for(int i = 2; i <= N; i++)
28     {
29         ans+=s(x[i], x[i-1], y[i], y[i-1]);
30     }
31     ans+=s(x[1], x[N], y[1], y[N]);
32     ans+=(2*pi*R);
33     printf("%.2lf\n", ans);
34     return 0;
35 }

 

POJ 2365【YY水题】

标签:col   different   div   contain   根据   include   into   小数点   0ms   

原文地址:https://www.cnblogs.com/ymzjj/p/9393643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!