-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path11040.go
46 lines (40 loc) · 828 Bytes
/
11040.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
// UVa 11040 - Add bricks in the wall
package main
import (
"fmt"
"os"
)
const row = 9
func solve(wall [][]int) {
for i := 2; i < row; i += 2 {
for j := 1; j < i; j += 2 {
wall[i][j] = (wall[i-2][j-1] - wall[i][j-1] - wall[i][j+1]) / 2
}
for j := 0; j < i; j++ {
wall[i-1][j] = wall[i][j] + wall[i][j+1]
}
}
}
func main() {
in, _ := os.Open("11040.in")
defer in.Close()
out, _ := os.Create("11040.out")
defer out.Close()
var kase int
for fmt.Fscanf(in, "%d", &kase); kase > 0; kase-- {
wall := make([][]int, row)
for i := range wall {
wall[i] = make([]int, i+1)
for j := range wall[i] {
if i%2 == 0 && j%2 == 0 {
fmt.Fscanf(in, "%d", &wall[i][j])
}
}
}
solve(wall)
for _, w := range wall {
line := fmt.Sprint(w)
fmt.Fprintln(out, line[1:len(line)-1])
}
}
}