-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy path102.go
47 lines (41 loc) · 899 Bytes
/
102.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
// UVa 102 - Ecological Bin Packing
package main
import (
"fmt"
"math"
"os"
)
const (
b = iota
c
g
)
var (
binColor = [][3]int{{b, c, g}, {b, g, c}, {c, b, g}, {c, g, b}, {g, b, c}, {g, c, b}}
binCode = []byte{'B', 'C', 'G'}
)
func main() {
in, _ := os.Open("102.in")
defer in.Close()
out, _ := os.Create("102.out")
defer out.Close()
var bin [3][3]int
var idx int
for {
total := 0
for i := 0; i < 3; i++ {
if _, err := fmt.Fscanf(in, "%d%d%d", &bin[i][b], &bin[i][g], &bin[i][c]); err != nil {
return
}
total += bin[i][b] + bin[i][g] + bin[i][c]
}
minMove := math.MaxInt32
for i, v := range binColor {
if move := total - bin[0][v[0]] - bin[1][v[1]] - bin[2][v[2]]; move < minMove {
minMove = move
idx = i
}
}
fmt.Fprintf(out, "%c%c%c %d\n", binCode[binColor[idx][0]], binCode[binColor[idx][1]], binCode[binColor[idx][2]], minMove)
}
}