首页 > 代码库 > URAL 1020 Rope

URAL 1020 Rope

Java的类库还是能省点力气的……

 1 import java.awt.geom.Point2D; 2 import java.util.Scanner; 3  4 public class P1020 5 { 6     public static void main(String args[]) 7     { 8         try (Scanner cin = new Scanner(System.in)) 9         {10             while (cin.hasNext())11             {12                 int n = cin.nextInt();13                 double r = cin.nextDouble();14                 Point2D.Double points[] = new Point2D.Double[n];15                 for (int i = 0; i < n; i++)16                     points[i] = new Point2D.Double(cin.nextDouble(), cin.nextDouble());17                 double result = 2 * Math.PI * r;18                 if (n > 1)19                 {20                     for (int i = 1; i < n; i++)21                         result += points[i].distance(points[i - 1]);22                     result += points[n - 1].distance(points[0]);23                 }24                 System.out.println(String.format("%.2f", result));25             }26         }27     }28 }

 

URAL 1020 Rope