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

最新文章

  1. NV显卡Ubuntu14.04更新软件导致登录死循环,不过可以进入tty模式
  2. 阿里云分布式关系数据库DRDS笔记
  3. 攻城狮在路上(贰) Spring(一)--- 软件环境、参考书目等一览表
  4. mac攻略(四) -- brew使用
  5. HTML表格与列表
  6. [转]SecureCRT连接主机时,无法从键盘输入
  7. UVa10023手动开大数平方算法
  8. 设置正确的post数据格式
  9. 53.转:深入浅出FPGA-14-ChipScope软件使用
  10. shell脚本应用(4)--常用命令
  11. 论docker中 CMD 与 ENTRYPOINT 的区别(转)
  12. CSS,注意点!!!!!!!
  13. j2ee中的2是什么意思
  14. sql统计总和和各状态数
  15. 金融量化分析【day112】:股票数据分析Tushare2
  16. django中云存储静态文件
  17. [转] Vmware vs Virtualbox vs KVM vs XEN: virtual machines performance comparison
  18. SpringSecurity项目中如何在多个模块中配置认证信息
  19. Flutter开发中的几个常用函数
  20. C++时间标准库时间time

热门文章

  1. node之Express框架
  2. Git~分支真的很轻
  3. linux安装PHP加速器eAccelerator
  4. 如何在ThinkPHP中开启调试模式
  5. 九度oj题目1014:排名
  6. AI从入门到放弃:CNN的导火索,用MLP做图像分类识别?
  7. android device ID获取
  8. ubuntu系统没有声音解决方法
  9. java几种常见的排序算法总结
  10. Sass学习笔记(三)