2013
11-11

# Rope

Plotters have barberically hammered N nails into an innocent plane shape, so that one can see now only heads. Moreover, pursuing their mean object, they have hammered all the nails into the vertices of a convex polygon. After that they…it is awful… have roped off the nails, so that the shape felt upset (the rope was very thin). They’ve done it as it is shown in the figure.

There two numbers in the first line of the standard input: N — a number of nails (1 <= N <= 100), and a real number R — a radius of heads of nails. All the heads have the same radius. Further there are N lines, each of them contains a pair of real coordinates (separated by a space) of centers of nails. An absolute value of the coordinates doesn't exceed 100. The nails are described in a clockwise order starting from an arbitrary nail. Heads of different nails don't adjoin.

The standard output should contain in its only line a real number with two digits precision (after a decimal point) — a length of the rope.

4 1
0.0 0.0
2.0 0.0
2.0 2.0
0.0 2.0


14.28

//* @author popop0p0popo
import java.util.*;
import java.io.*;

public class Main{
public static void main(String[] args){
int n=scanner.nextInt();
double r=scanner.nextDouble();
double[] x=new double[n];
double[] y=new double[n];
for (int i=0;i< n ;i++ ){
x[i]=scanner.nextDouble();
y[i]=scanner.nextDouble();
}
double l=2*r*Math.PI;
for (int i=0;i < n ;i++ ){
if (i!=n-1){
l=l+Math.sqrt((x[i]-x[i+1])*(x[i]-x[i+1])+(y[i]-y[i+1])*(y[i]-y[i+1]));
}
else{
l=l+Math.sqrt((x[i]-x[0])*(x[i]-x[0])+(y[i]-y[0])*(y[i]-y[0]));
}
}
l=Math.round(l*100.0)/100.0;
System.out.println(l);
}
}

1. 您没有考虑 树的根节点是负数的情况， 若树的根节点是个很大的负数，那么就要考虑过不过另外一边子树了

2. 问题3是不是应该为1/4 .因为截取的三段，无论是否能组成三角形， x， y-x ，1-y,都应大于0，所以 x<y,基础应该是一个大三角形。小三角是大三角的 1/4.