-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path534.go
50 lines (44 loc) · 1.03 KB
/
534.go
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
48
49
50
// UVa 534 - Frogger
package main
import (
"fmt"
"math"
"os"
)
type stone struct{ x, y float64 }
func floydWarshall(n int, stones []stone) float64 {
minMax := make([][]float64, n)
for i := range minMax {
minMax[i] = make([]float64, n)
for j := range minMax[i] {
minMax[i][j] = math.Sqrt((stones[i].x-stones[j].x)*(stones[i].x-stones[j].x) + (stones[i].y-stones[j].y)*(stones[i].y-stones[j].y))
}
}
for k := range stones {
for i := range stones {
for j := range stones {
minMax[i][j] = min(minMax[i][j], max(minMax[i][k], minMax[k][j]))
}
}
}
return minMax[0][1]
}
func main() {
in, _ := os.Open("534.in")
defer in.Close()
out, _ := os.Create("534.out")
defer out.Close()
var n int
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
stones := make([]stone, n)
for i := range stones {
fmt.Fscanf(in, "%f%f", &stones[i].x, &stones[i].y)
}
fmt.Fscanln(in)
fmt.Fprintf(out, "Scenario #%d\n", kase)
fmt.Fprintf(out, "Frog Distance = %.3f\n\n", floydWarshall(n, stones))
}
}