zoukankan      html  css  js  c++  java
  • 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

     

    题目大意:

    有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
    ", ans);
    34     return 0;
    35 }
  • 相关阅读:
    Jmeter分布测试
    SQL命令
    Linux执行命令时遇到的些问题
    Linux常用命令总结
    Jenkins与SVN持续集成
    在linux上创建slave节点
    内网域名配置方法
    Java中重写与重载的区别
    MongoDB基本使用
    MongoDB安装
  • 原文地址:https://www.cnblogs.com/ymzjj/p/9393643.html
Copyright © 2011-2022 走看看