-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path10310.go
More file actions
47 lines (40 loc) · 893 Bytes
/
10310.go
File metadata and controls
47 lines (40 loc) · 893 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// UVa 10310 - Dog and Gopher
package main
import (
"fmt"
"math"
"os"
)
type point struct{ x, y float64 }
func distance(p1, p2 point) float64 {
return math.Sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y))
}
func main() {
in, _ := os.Open("10310.in")
defer in.Close()
out, _ := os.Create("10310.out")
defer out.Close()
var n int
var gopher, dog, p point
for {
if _, err := fmt.Fscanf(in, "%d", &n); err != nil {
break
}
fmt.Fscanf(in, "%f%f", &gopher.x, &gopher.y)
fmt.Fscanf(in, "%f%f", &dog.x, &dog.y)
found := false
for ; n > 0; n-- {
fmt.Fscanf(in, "%f%f", &p.x, &p.y)
if distance(p, gopher)*2 <= distance(p, dog) {
found = true
break
}
}
if !found {
fmt.Fprintln(out, "The gopher cannot escape.")
} else {
fmt.Fprintf(out, "The gopher can escape through the hole at (%.3f,%.3f).\n", p.x, p.y)
}
fmt.Fscanln(in)
}
}