Time Limit: 2 seconds memory limit: 65536 KB
A large field has a dog and a gopher. The dog wants to eat the gopher, while the gopher wants to run to safety through one of several gopher holes dug in the surface of the field.
Neither the dog nor the gopher is a math major; however, neither is entirely stupid. the gopher decides on a particle gopher hole and heads for that hole in a straight line at a fixed speed. the dog, which is very good at reading body language, anticipates which hole the gopher has chosen, and heads at double the speed of the gopher to the hole, where it intends to gobble up the gopher. if the dog reaches the hole first, the gopher gets gobbled; otherwise, the gopher escapes.
You have been retained by the gopher to select a hole through which it can escape, if such a hole exists.
Input
The first line of input contains four floating point numbers: the (x, y) coordinates of the gopher followed by the (x, y) coordinates of the dog. subsequent lines of input each contain two floating point numbers: the (x, y) coordinates of a gopher hole. all distances are in metres, to the nearest mm.
Input contains multiple test cases. Subsequent test cases are separated with a single blank line.
Output
Your output for each test case shoshould consist of a single line. if the gopher can escape the line shocould read "the gopher can escape through the hole at (x, y ). "identifying the appropriate hole to the nearest mm. otherwise the output line shocould read "the gopher cannot escape. "If the gopher may escape through more than one hole, choose the first one. there are not more than 1000 gopher holes and all coordinates are between-10000 and + 10000.
Sample Input
1.000 1.000 2.000 2.000
1.500 1.500
2.000 2.000 1.000 1.000
1.500 1.500
2.500 2.500
Sample output
The gopher cannot escape.
The gopher can escape through the hole at (2.500, 2.500 ).
Source:University of Waterloo local contest %9.25
1: # include <iostream>
2: # include <String>
3: # include <sstream>
4: # include <limits>
5: # include <stdio. h>
6:Using NamespaceSTD;
7:DoubleDistance (DoubleX1,DoubleY1,DoubleX2,DoubleY2)
8 :{
9:Return(X1-X2) * (x1-X2) + (Y1-Y2) * (Y1-Y2 );
10 :}
11:IntMain (Void)
12 :{
13:StringCoordinates;
14:While(Getline (CIN, coordinates ))
15 :{
16:If(Coordinates = "")Continue;
17:StringHoleposition;
18:DoubleX_dog, y_dog, x_gopher, y_gopher;
19:DoubleX_hole, y_hole;
20: istringstream is (coordinates );
21: Is> x_gopher> y_gopher> x_dog> y_dog;
22:BoolCatched =True;
23:DoubleNearestdistance =-1, crtdistance, x_nearest, y_nearest;
24:While(Getline (CIN, holeposition ))
25 :{
26:If(Holeposition = "")Break;
27: istringstream is0 (holeposition );
28: is0> x_hole> y_hole;
29: crtdistance = distance (x_gopher, y_gopher, x_hole, y_hole );
30:If(Distance (x_dog, y_dog, x_hole, y_hole)> 4 * distance (x_gopher, y_gopher, x_hole, y_hole ))
31 :{
32: catched =False;
33:If(Nearestdistance> crtdistance)
34 :{
35: nearestdistance = crtdistance;
36: x_nearest = x_hole;
37: y_nearest = y_hole;
38 :}
39 :}
40 :}
41:If(! Catched)
42 :{
43: printf ("The gopher can escape through the hole at (%. 3f, %. 3f). \ n", X_nearest, y_nearest );
44 :}
45:Else
46 :{
47: cout <"The gopher cannot escape."<Endl;
48 :}
49 :}
50:Return0;
51 :}