-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy path10360.go
More file actions
53 lines (46 loc) · 954 Bytes
/
10360.go
File metadata and controls
53 lines (46 loc) · 954 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
48
49
50
51
52
53
// UVa 10360 - Rat Attack
package main
import (
"fmt"
"io"
"os"
)
const max = 1025
func process(d, x, y, population int, rats *[max][max]int) {
for i := x - d; i <= x+d; i++ {
if i >= 0 && i < max {
for j := y - d; j <= y+d; j++ {
if j >= 0 || j < max {
rats[i][j] += population
}
}
}
}
}
func output(out io.Writer, rats *[max][max]int) {
max, x, y := 0, 0, 0
for i := range rats {
for j := range rats[i] {
if rats[i][j] > max {
max = rats[i][j]
x, y = i, j
}
}
}
fmt.Fprintln(out, x, y, max)
}
func main() {
in, _ := os.Open("10360.in")
defer in.Close()
out, _ := os.Create("10360.out")
defer out.Close()
var kase, d, n, x, y, population int
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
var rats [max][max]int
for fmt.Fscanf(in, "%d\n%d", &d, &n); n > 0; n-- {
fmt.Fscanf(in, "%d%d%d", &x, &y, &population)
process(d, x, y, population, &rats)
}
output(out, &rats)
}
}