ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1020. Rope

Correct code in JAVA ( 0.093 s )
Posted by Vahid Khodabakhshi 12 Nov 2009 13:16
import java.util.Scanner;
public class _1020
{
    public static void main( String[] args )
    {
        Scanner in = new Scanner( System.in );
        int N = in.nextInt();
        double R = in.nextDouble();
        double[][] p = new double[N][2];
        double PI = Math.PI;
        double L = 2*PI*R;
        for( int i=0 ; i<N ; i++ )
        {
            p[i][0] = in.nextDouble();
            p[i][1] = in.nextDouble();
            if( i>0 )    L += Math.sqrt( (p[i][1]-p[i-1][1])*(p[i][1]-p[i-1][1]) + (p[i][0]-p[i-1][0])*(p[i][0]-p[i-1][0]) );
        }
        L += Math.sqrt( (p[0][1]-p[N-1][1])*(p[0][1]-p[N-1][1]) + (p[0][0]-p[N-1][0])*(p[0][0]-p[N-1][0]) );
        System.out.println( String.format("%.2f", L) );
    }
}