Back to list of problems
Ecological Bin Packing
102.c
/* Brute Force */ #include <stdio.h> #include <limits.h> int main() { char buf[1024]; int b[3]; int g[3]; int c[3]; int min; char *label="BCG"; int i; while(fgets(buf,1024,stdin)) { if (sscanf(buf,"%d %d %d %d %d %d %d %d %d", &b[1],&g[1],&c[1],&b[2],&g[2],&c[2],&b[3],&g[3],&c[3])!=9) { printf("error\n"); continue; } min = b[2]+b[3]+c[1]+c[3]+g[1]+g[2]; /* BCG */ label="BCG"; i = b[2]+b[3]+g[1]+g[3]+c[1]+c[2]; /* BGC */ if (i<min) { min=i; label="BGC"; } i = c[2]+c[3]+b[1]+b[3]+g[1]+g[2]; /* CBG */ if (i<min) { min=i; label="CBG"; } i = c[2]+c[3]+g[1]+g[3]+b[1]+b[2]; /* CGB */ if (i<min) { min=i; label="CGB"; } i = g[2]+g[3]+b[1]+b[3]+c[1]+c[2]; /* GBC */ if (i<min) { min=i; label="GBC"; } i = g[2]+g[3]+c[1]+c[3]+b[1]+b[2]; /* GCB */ if (i<min) { min=i; label="GCB"; } printf("%s %d\n", label, min); } exit(0); }