-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdoggopher.java
31 lines (29 loc) · 1.13 KB
/
doggopher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
import java.math.*;
import java.io.*;
public class doggopher {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(in.readLine());
double gx = Double.parseDouble(st.nextToken());
double gy = Double.parseDouble(st.nextToken());
double dx = Double.parseDouble(st.nextToken());
double dy = Double.parseDouble(st.nextToken());
String line = "";
boolean escaped = false;
while((line = in.readLine()) != null) {
st = new StringTokenizer(line);
double hx = Double.parseDouble(st.nextToken());
double hy = Double.parseDouble(st.nextToken());
if(Math.hypot(Math.abs(gx - hx), Math.abs(gy - hy)) * 2 < Math.hypot(Math.abs(dx - hx), Math.abs(dy - hy))) {
out.println("The gopher can escape through the hole at (" + String.format("%.3f", hx) + "," + String.format("%.3f", hy) + ").");
escaped = true;
}
}
if(!escaped) {
out.println("The gopher cannot escape.");
}
out.close();
}
}