题目链接: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. Manacher算法(马拉车)

    学习博客:https://www.cnblogs.com/love-yh/p/7072161.html 首先,得先了解什么是回文串(我之前就不是很了解,汗).回文串就是正反读起来就是一样的,如“abb ...

  2. flex buider 4.6 打开设计模式(designer)时提示内存不足错误的解决办法

    先申明,此方法只适用于flex builder 4.6及以下版本, flex builder 4.7以后已经完全取消了designer功能,是没有办法补救的. 1. 首先下载APE文件,这个文件好像是 ...

  3. Shader学习笔记

    Shader学习笔记 例子: Shader "SrfShader1"{ //定义显示在Inspector中的变量,并从Inspector中获取值 Properties{ _Colo ...

  4. Mysql数据库死锁分析相关概念

    参考博客: mysql死锁问题分析(https://www.cnblogs.com/LBSer/p/5183300.html) mysql insert锁机制(http://yeshaoting.cn ...

  5. tomcat server 报错之 More than the maximum allowed number of cookies

    More than the maximum allowed number of cookies EVERE: Error processing request java.lang.IllegalArg ...

  6. 位运算(6)——Number Complement

    Given a positive integer, output its complement number. The complement strategy is to flip the bits ...

  7. iOS开发之GCD基础

    重新回顾.学习GCD.Block.先贴出一篇不错的讲解GCD基础使用的文章 原文地址:http://blog.csdn.net/aolan1108/article/details/17283415 做 ...

  8. IO流之File类

    IO概述: 程序数据都是在内存中,程序运行结束,这些数据将清空,数据都都不能保存下来,下次程序启动的时候,想再把这些数据读出来继续使用,把数据持久化存储,就需要把内存中的数据存储到内存以外的其他持久化 ...

  9. Csharp:操作存儲過程輸出參數,和返回值

    /// <summary> ///塗聚文 存儲過程輸出參數,和返回值 /// 20131030 /// Geovin Du /// </summary> /// <par ...

  10. javascript实现数据结构: 树和二叉树的应用--最优二叉树(赫夫曼树),回溯法与树的遍历--求集合幂集及八皇后问题

    赫夫曼树及其应用 赫夫曼(Huffman)树又称最优树,是一类带权路径长度最短的树,有着广泛的应用. 最优二叉树(Huffman树) 1 基本概念 ① 结点路径:从树中一个结点到另一个结点的之间的分支 ...