Vijos 1007 饶钉子的长绳子

来源:互联网 发布:淘宝的恒源祥是正品吗 编辑:程序博客网 时间:2024/05/01 02:48

给出钉子坐标 和钉子半径 求绕起来的绳子长度。

其实就是所有钉子圆心组成的凸多边形的周长+一个半径为r的圆;

AC代码:

#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;struct lx{    double x,y;}L[101];const double T=3.1415926;int main(){    int n;    double r;    while(cin>>n>>r)    {        for(int i=0;i<n;i++)        cin>>L[i].x>>L[i].y;        double ans=2*T*r;        for(int i=1;i<n;i++)        {            ans+=sqrt(pow(L[i].x-L[i-1].x,2)+pow(L[i].y-L[i-1].y,2));        }        ans+=sqrt(pow(L[n-1].x-L[0].x,2)+pow(L[n-1].y-L[0].y,2));        printf("%.2lf\n",ans);    }}


0 0