Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
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);
}