Created
May 15, 2019 08:57
-
-
Save jongha/b8f69928b00771987fa67ebcad137a62 to your computer and use it in GitHub Desktop.
UVa 102 - Ecological Bin Packing, http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <vector> | |
#include <list> | |
#include <algorithm> | |
#include <string.h> | |
#include <string> | |
#include <queue> | |
#include <stack> | |
#include <math.h> | |
#define MAX 3 | |
#define INF 2147483647 | |
int in[3][3]; | |
int main(void) { | |
while(true) { | |
int ret = scanf("%d %d %d %d %d %d %d %d %d", | |
&in[0][0], &in[0][2], &in[0][1], | |
&in[1][0], &in[1][2], &in[1][1], | |
&in[2][0], &in[2][2], &in[2][1]); | |
if(ret == EOF) break; | |
int m = INF; | |
int mi = 0, mj = 0, mk = 0; | |
for(int i=0; i<MAX; ++i) { | |
for(int j=0; j<MAX; ++j) { | |
if(i == j) continue; | |
for(int k=0; k<MAX; ++k) { | |
if(i == k || j == k) continue; | |
int sum = 0; | |
for(int a=0; a<MAX; ++a) sum += (i != a) ? in[0][a] : 0; | |
for(int a=0; a<MAX; ++a) sum += (j != a) ? in[1][a] : 0; | |
for(int a=0; a<MAX; ++a) sum += (k != a) ? in[2][a] : 0; | |
if(sum < m) { | |
m = sum; | |
mi = i; mj = j; mk = k; | |
} | |
} | |
} | |
} | |
char c[3] = {'B', 'C', 'G'}; | |
printf("%c%c%c %d\n", c[mi], c[mj], c[mk], m); | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment