102.c

Back Download
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
/*
102.c
Solution to ACM problem #102 - "Ecological Bin Packing"
Matthew Eagar - meagar@gmail.com
Verified to work as of July 06 / 2009
This version is highly optimized for speed, with all the loops unrolled.
It is currently ranked 15th.
*/
#include <stdio.h>
#include <limits.h>
static const char* combos[] = { "GCB" , "GBC" , "CGB" , "CBG" , "BGC" , "BCG" };
#define check(x,y,z,i) if ((nMoves = n##x##1 + n##y##2 + n##z##3) <= bestNumMoves)\
{ best = i; bestNumMoves = nMoves; }
int main() {
int b1, g1, c1, b2, g2, c2, b3, g3, c3
, nb1, ng1, nc1, nb2, ng2, nc2, nb3, ng3, nc3
, best, bestNumMoves, nMoves;
while (EOF != scanf("%d %d %d %d %d %d %d %d %d"
, &b1, &g1, &c1, &b2, &g2, &c2, &b3, &g3, &c3)) {
nb1 = g1 + c1;
ng1 = b1 + c1;
nc1 = b1 + g1;
nb2 = g2 + c2;
ng2 = b2 + c2;
nc2 = b2 + g2;
nb3 = g3 + c3;
ng3 = b3 + c3;
nc3 = b3 + g3;
best = 1;
bestNumMoves = INT_MAX;
check(g, c, b, 0);
check(g, b, c, 1);
check(c, g, b, 2);
check(c, b, g, 3);
check(b, g, c, 4);
check(b, c, g, 5);
printf("%s %d\n", combos[best], bestNumMoves);
}
return 0;
}