NOJ[1397] 绳子的长度

来源:互联网 发布:移动网络部门岗位职责 编辑:程序博客网 时间:2024/06/10 03:51
  • 问题描述
  • 平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。

    现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。

    求出绳子的长度

  • 输入
  • 第1行两个数:整数N(1<=N<=100)和实数R。
    接下来N行按逆时针顺序给出N个钉子中心的坐标坐标的绝对值不超过100。
  • 输出
  • 一个数,绳子的长度,精确到小数点后2位。
  • 样例输入
  • 4 10.0 0.02.0 0.02.0 2.00.0 2.0
  • 样例输出
  • 14.28
  • 提示
  • 来源
  • @HBMY-JZQ
你确定你觉得这是凸包?

其实这是水题。for一遍计算长度,然后加上个圆的周长

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>

double pi=acos(-1);

int main()
{
int n;
double r;
while(~scanf("%d%lf",&n,&r))
{
double len=2*r*pi,x,y,lastx,lasty,x0,y0;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&x,&y);
if(i==0)
{
x0=lastx=x;
y0=lasty=y;
}
else
{
len+=(double)sqrt((x-lastx)*(x-lastx)+(y-lasty)*(y-lasty));
lastx=x;
lasty=y;
}
}
len+=(double)sqrt((lastx-x0)*(lastx-x0)+(y0-lasty)*(y0-lasty));
printf("%.2f\n",len);

}
}



0 0