/** * Dog and Gopher Problem. * * @author John Paxton * @version June 4, 2014 */ import java.io.*; import java.util.Scanner; public class Gopher { public static void main (String [] args) throws FileNotFoundException { int holes; double gopherX, gopherY; double dogX, dogY; Scanner in = new Scanner (new File ("gopher.in")); PrintWriter out = new PrintWriter (new File ("desired.out")); double holeX = 0.0, holeY = 0.0; boolean escape; while (in.hasNext()) { holes = in.nextInt(); gopherX = in.nextDouble(); gopherY = in.nextDouble(); dogX = in.nextDouble(); dogY = in.nextDouble(); escape = false; for (int hole = 0; hole < holes; hole++) { holeX = in.nextDouble(); holeY = in.nextDouble(); if (!escape && canEscape(gopherX, gopherY, dogX, dogY, holeX, holeY)) { escape = true; out.format("The gopher can escape through the hole at (%.3f,%.3f).\n", holeX, holeY); } } if (!escape) { out.println("The gopher cannot escape."); } } out.close(); } private static boolean canEscape(double gX, double gY, double dX, double dY, double hX, double hY) { return (2 * distance(gX, gY, hX, hY) <= distance(dX, dY, hX, hY)); } private static double distance (double x1, double y1, double x2, double y2) { return Math.sqrt((y2 - y1)*(y2 - y1) + (x2 - x1)*(x2 - x1)); } }