Rokua a long rope around a nail

Source: Internet
Author: User

Background

There are n cylindrical large nails on the plane, the radius is r, and all the nails form a convex polygon.

Now you're going to surround these nails with a rope, and the rope's diameter is negligible.

Describe

Find out the length of the rope

Format input Format

Line 1th two number: integer N (1<=n<=100) and real R.

The next n lines give the coordinates of the center of N Nails in a counterclockwise order
The absolute value of the coordinate does not exceed 100.

Output format

A number, the length of the rope, exactly 2 digits after the decimal point.

Example 1 Sample Input 1
4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0
Sample Output 1
14.28
Limit

Each test point 1s

Tips

If you're using a more complex method of AC, think about whether there's a simpler way.

Find the law, no matter how much n is the distance between his two points plus a circle can draw their own.

#include <iostream>#include<cstring>#include<cstdio>#include<cmath>using namespacestd;Const DoublePi=acos (-1.0);intI,j,n;Doubler,x[101],y[101],ans;intMain () {scanf ("%D%LF",&n,&s);  for(i=0; i<n;++i) {scanf ("%LF%LF",&x[i],&Y[i]); if(i>=1) Ans+=sqrt ((x[i]-x[i-1]) * (x[i]-x[i-1]) + (y[i]-y[i-1]) * (y[i]-y[i-1])); if(i==n-1) Ans+=sqrt ((x[i]-x[0]) * (x[i]-x[0]) + (y[i]-y[0]) * (y[i]-y[0])); } ans+=r*2*Pi; printf ("%.2LF", ans);}

Rokua a long rope around a nail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.