zoukankan      html  css  js  c++  java
  • 迷茫时就切两道--借用

    背景
    平面上有N个圆柱形的大钉子,半径都为R,所有钉子组成一个凸多边形。
    现在你要用一条绳子把这些钉子围起来,绳子直径忽略不计。
    描述
    求出绳子的长度
    格式
    输入格式
    第1行两个数:整数N(1<=N<=100)和实数R。
    接下来N行按逆时针顺序给出N个钉子中心的坐标
    坐标的绝对值不超过100。
    输出格式
    一个数,绳子的长度,精确到小数点后2位。
    样例1
    样例输入1[复制]
    4 1
    0.0 0.0
    2.0 0.0
    2.0 2.0
    0.0 2.0
    样例输出1[复制]
    14.28
    限制
    各个测试点1s

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    #define p 3.1415926
    using namespace std;
    class Length
    {
        public:
        float x;
        float y;
    
    };
    int  Len(Length &a,Length &b)
    {
        return (sqrt(pow((a.x-b.x),2)+pow((a.y-b.y),2)));
    }
    
    int main()
    {
        float s=0;
        int N,R;
        int i;
        Length now,last,first;
        cin>>N>>R;
        cin>>first.x>>first.y;
        last.x=first.x;
        last.y=first.y;
        for(i=1;i<N;i++)
        {
        cin>>now.x>>now.y;
        s=s+Len(now,last);
        last.x=now.x;
        last.y=now.y;
    
        }
        s=s+Len(now,first)+2*p*R;
        printf("%.2f",s);
        return 0;
    
    }
  • 相关阅读:
    Wannafly挑战赛9
    acm之图论基础
    Codeforces Round #459 (Div. 2)
    Codeforces Round #460 (Div. 2)
    浙南联合训练赛20180129
    AtCoder Regular Contest 090
    牛客练习赛11
    2018年1月26日天梯赛练习1
    csa Round #66 (Div. 2 only)
    EOJ Monthly 2018.1
  • 原文地址:https://www.cnblogs.com/yaobolove/p/4127377.html
Copyright © 2011-2022 走看看