-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path10849.go
46 lines (39 loc) · 832 Bytes
/
10849.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 10849 - Move the bishop
package main
import (
"fmt"
"os"
)
type cell struct{ row, column int }
func abs(a int) int {
if a < 0 {
return -a
}
return a
}
func solve(bishop, target cell) string {
switch dr, dc := abs(bishop.row-target.row), abs(bishop.column-target.column); {
case dr == 0 && dc == 0:
return "0"
case dr == dc:
return "1"
case abs(dr-dc)%2 == 1:
return "no move"
default:
return "2"
}
}
func main() {
in, _ := os.Open("10849.in")
defer in.Close()
out, _ := os.Create("10849.out")
defer out.Close()
var c, t, n int
var bishop, target cell
for fmt.Fscanf(in, "%d", &c); c > 0; c-- {
for fmt.Fscanf(in, "\n%d\n%d", &t, &n); t > 0; t-- {
fmt.Fscanf(in, "%d%d%d%d", &bishop.row, &bishop.column, &target.row, &target.column)
fmt.Fprintln(out, solve(bishop, target))
}
}
}