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

 #include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define pi 3.1415
using namespace std; const int MAXN = ; double x[MAXN], y[MAXN];
double ans, R;
int N; double s(double x1, double x2, double y1, double y2)
{
return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
} int main()
{
scanf("%d%lf", &N, &R);
for(int i = ; i <= N; i++)
{
scanf("%lf %lf", &x[i], &y[i]);
}
for(int i = ; i <= N; i++)
{
ans+=s(x[i], x[i-], y[i], y[i-]);
}
ans+=s(x[], x[N], y[], y[N]);
ans+=(*pi*R);
printf("%.2lf\n", ans);
return ;
}

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

  1. POJ 2365 Rope(水题)

    [题意简述]:给出我们钉子个数与半径,让我们求出缠绕在钉子上的绳子有多长. [分析]:从题目中我们能够看出,绳子长度的和等于每两个钉子的距离的和加上接触在钉子上的绳子的长度,不难发现这部分长度事实上就 ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. poj 3264 RMQ 水题

    题意:找到一段数字里最大值和最小值的差 水题 #include<cstdio> #include<iostream> #include<algorithm> #in ...

  4. Poj 1552 Doubles(水题)

    一.Description As part of an arithmetic competency program, your students will be given randomly gene ...

  5. 最小费用最大流模板 poj 2159 模板水题

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15944   Accepted: 8167 Descr ...

  6. POJ 1837 Balance 水题, DP 难度:0

    题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...

  7. POJ - 3090 gcd水题

    大概题意就是求\(1 \le i,j \le n\)的\(gcd(i,j) = 1\)的个数+2(对于0的特判) 正解应该是欧拉函数或者高逼格的莫比乌斯反演 但数据实在太水直接打表算了 /*H E A ...

  8. POJ 3256 DFS水题

    枚举点 每次都搜一遍 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  9. POJ 1654 Area(水题)

    题目链接 卡了一下精度和内存. #include <cstdio> #include <cstring> #include <string> #include &l ...

随机推荐

  1. Notepad++的ftp远程编辑功能

    我们主要来说说NppFTP的使用方法: 1.启动notepad++后,点击插件-->NppFTP-->Show NppFTP Window,就可以显示NppFTP的管理窗口了. 2.在Np ...

  2. HTTP和HTTPS的区别?

    HTTP1.1(Hypertext Transfer Protocol Vertion 1.1)超文本传输协议-版本1.1它是用来在Internet上传送超文本的传送协议.它是运行在Tcp/Ip协议族 ...

  3. spark scala 例子

    object ScalaApp { def main(args: Array[String]): Unit = { var conf = new SparkConf() conf.setMaster( ...

  4. 今天研究Unity Ioc 框架

    今天研究Unity Ioc 框架,被自己坑了两个多小时. 运行就报错,反反复复检查了很多次,配置文件,代码都没有问题,也从新写了好几遍. 最后仔细看报错消息才知道,config文件没有生成到目录……… ...

  5. 【Linux】安装Nginx

    注:转自https://www.cnblogs.com/hdnav/p/7941165.html 安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Window ...

  6. Python 显示调用栈

    Python调试不如强类型的语言方便,显示调用栈有时非常必要,inspect模块很好用 import inspect inspect.stack() inspect.stack()返回的是一个函数栈帧 ...

  7. 二维数组针对某字段排序 - array_multisort()

    /** * 针对二维数组下的某字段排序 * @param array $myarr 被排序数组 * @param string $sort_key 排序根据字段 * @param flag $sort ...

  8. c++sizeof大全

    sizeof,一个其貌不扬的家伙,引无数菜鸟竟折腰,小虾我当初也没少犯迷糊,秉着“辛苦我一个,幸福千万人”的伟大思想,我决定将其尽可能详细的总结一下.但当我总结的时候才发现,这个问题既可以简单,又可以 ...

  9. JS基础学习——作用域

    JS基础学习--作用域 什么是作用域 变量的作用域就是变量能被访问到的代码范围,比如在下面的这个js代码中,变量a的作用域就是函数foo,因此在全局作用域内的console.log(a)语句不能访问到 ...

  10. jquery mobile 自定义图标

    Jquery Mobile框架包含了一组最常用的移动应用程序所需的图标,为了减少下载的大小,Jquery Mobile包含的是的白色的图标sprite图片,并自动在图标后添加一个半透明的黑圈以确保在任 ...