-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10703.go
65 lines (59 loc) · 1.11 KB
/
10703.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
53
54
55
56
57
58
59
60
61
62
63
64
65
// UVa 10703 - Free spots
package main
import (
"fmt"
"os"
)
func cover(board [][]bool, x1, y1, x2, y2 int) {
if x2 < x1 {
x1, x2 = x2, x1
}
if y2 < y1 {
y1, y2 = y2, y1
}
for i := x1 - 1; i < x2; i++ {
for j := y1 - 1; j < y2; j++ {
board[i][j] = true
}
}
}
func uncovered(board [][]bool) int {
var count int
for _, vi := range board {
for _, vj := range vi {
if !vj {
count++
}
}
}
return count
}
func main() {
in, _ := os.Open("10703.in")
defer in.Close()
out, _ := os.Create("10703.out")
defer out.Close()
var w, h, n, x1, y1, x2, y2 int
for {
if fmt.Fscanf(in, "%d%d%d", &w, &h, &n); w == 0 && h == 0 && n == 0 {
break
}
board := make([][]bool, w)
for i := range board {
board[i] = make([]bool, h)
}
for ; n > 0; n-- {
fmt.Fscanf(in, "%d%d%d%d", &x1, &y1, &x2, &y2)
cover(board, x1, y1, x2, y2)
}
fmt.Fscanln(in)
switch count := uncovered(board); count {
case 0:
fmt.Fprintln(out, "There is no empty spots.")
case 1:
fmt.Fprintln(out, "There is one empty spot.")
default:
fmt.Fprintf(out, "There are %d empty spots.\n", count)
}
}
}