import java.awt.geom.Point2D; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; /** * Solution to SMove Away * * @author vanb */ public class moveaway_vanb { private static Scanner sc; private static PrintStream ps; private static final double EPSILON = 0.000001; /** * Info about a Friend - location, and distance. * * @author vanb */ private class Friend { /** Location */ double x, y; /** Distance */ double d; /** * Create a Friend. * * @param x X coord of location * @param y Y coord of location * @param d Distance */ public Friend( double x, double y, double d ) { this.x = x; this.y = y; this.d = d; } } /** * Law of Cosines! EXTREMELY useful. * * The LoC says that for any triangle, if a, b, and c are its side lengths, * and theta is the angle between a and b (opposite c), then: * * c^2 = a^2 + b^2 -2*a*b*cos(theta) * * Solve for theta, and we get cos(theta) = (a^2+b^2-c^2)/(2*a*b), * or theta = arccos[(a^2+b^2-c^2)/(2*a*b)] * * @param a Leg of a triangle adjacent to theta * @param b The other leg of a triangle adjacent to theta * @param c Leg of a triangle opposite theta * @return theta */ private double loc( double a, double b, double c ) { return Math.acos( (a*a+b*b-c*c)/(2.0*a*b) ); } /** * Do it! */ private void doit() { int n = sc.nextInt(); Friend friends[] = new Friend[n]; for( int i=0; i candidates = new ArrayList (2*n*n); // Thinks of a circle, and an arbitraty point on that circle. // Move away from the origin along the edge. What's going to stop you from getting // further away from the origin? Two things: either the furthest point on the circle from the origin, // or an intersection with another circle. for( int i=0; ifriend.d + EPSILON ) { insideall = false; break; } } // Inside all circles? Check the distance to the origin. if( insideall ) { double dist = Math.hypot( candidate.y, candidate.x ); if( dist>maxdist ) maxdist = dist; } } ps.printf( "%.3f", maxdist ); ps.println(); } /** * Main! * * @param args Command-line args (not used) * @throws Exception */ public static void main( String[] args ) throws Exception { sc = new Scanner( System.in ); ps = System.out; new moveaway_vanb().doit(); } }