POJ 2365【YY水题】

题目链接: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

Ural State University Internal Contest October‘2000 Junior Session

题目大意:

有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 }

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

时间: 2024-10-25 15:02:08

POJ 2365【YY水题】的相关文章

POJ 2365 Rope(水题)

[题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们可以看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度其实就等于钉子的周长. 见代码: #include<iostream> #include<cmath> using namespace std; #define Pi 3.1415//这个精度要尽量高! 也可以用4.0*atan(1.0) double s(double x1,double y

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

poj 3264 RMQ 水题

题意:找到一段数字里最大值和最小值的差 水题 1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 using namespace std; 8 const int maxn=550; 9 const int INF=0x3f3f3f3f; 10 in

poj 1979 dfs水题

// 练练水题,夯实基础吧 #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib

POJ 1000(水题)

这道题就很水啦,只要看懂题...所以我受了这个影响,再去hoj的时候想都没想就还按照这个打了,结果就像之前那篇说的那样WA. #include <stdio.h> int main() { int a,b; scanf("%d %d",&a, &b); printf("%d\n",a+b); return 0; }

POJ - 3090 gcd水题

大概题意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的个数+2(对于0的特判) 正解应该是欧拉函数或者高逼格的莫比乌斯反演 但数据实在太水直接打表算了 /*H E A D*/ bool GCD[1002][1002]; inline int gcd(int a,int b){return b?gcd(b,a%b):a;} int main(){ rep(i,1,1000) rep(j,1,1000) GCD[i][j]=bool(gcd(i,j)==1); in

POJ - 3094 - Quicksum = 水题

http://poj.org/problem?id=3094 学习fgets的使用,注意fgets是会连换行一起保存的. #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<map> #include<set> #include<stack> #include<

POJ 3264 RMQ水题

题目大意就是有很多牛.告诉你每只牛的高度.然后有很多个询问.输出该区间内的最大身高差.也就是用RMQ求最大值最小值.貌似还可以用线段树.然而,我还不会线段树.....T_T 可能是太多组数据了.cin和cout会TLE.换成scanf和printf就顺当的AC了....啦啦啦. RMQ还是只会用模板..T_T 附代码:#include<stdio.h>#include<string.h>#include<iostream>#include<math.h>#d

POJ 3077-Rounders(水题乱搞)

Rounders Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7697   Accepted: 4984 Description For a given number, if greater than ten, round it to the nearest ten, then (if that result is greater than 100) take the result and round it to th