-
Notifications
You must be signed in to change notification settings - Fork 27
/
688.go
52 lines (46 loc) · 1.04 KB
/
688.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
51
52
// UVa 688 - Mobile Phone Coverage
package main
import (
"fmt"
"os"
"sort"
)
type antenna struct{ x, y, r float64 }
func solve(n int, antennas []antenna) float64 {
x, y := make([]float64, 2*n), make([]float64, 2*n)
for i, a := range antennas {
x[2*i], x[2*i+1] = a.x-a.r, a.x+a.r
y[2*i], y[2*i+1] = a.y-a.r, a.y+a.r
}
sort.Float64s(x)
sort.Float64s(y)
var area float64
for i := 0; i < 2*n-1; i++ {
for j := 0; j < 2*n-1; j++ {
for _, a := range antennas {
if a.x-a.r <= x[i] && a.x+a.r >= x[i+1] && a.y-a.r <= y[j] && a.y+a.r >= y[j+1] {
area += (x[i+1] - x[i]) * (y[j+1] - y[j])
break
}
}
}
}
return area
}
func main() {
in, _ := os.Open("688.in")
defer in.Close()
out, _ := os.Create("688.out")
defer out.Close()
var n int
for kase := 1; ; kase++ {
if fmt.Fscanf(in, "%d", &n); n == 0 {
break
}
antennas := make([]antenna, n)
for i := range antennas {
fmt.Fscanf(in, "%f%f%f", &antennas[i].x, &antennas[i].y, &antennas[i].r)
}
fmt.Fprintf(out, "%d %.02f\n", kase, solve(n, antennas))
}
}