#include<iostream> #include<stdio.h> #include<cstdio> using namespace std; string funct(int c1 , int c2 , int c3 , string s_temp , int temp , int temp_max); /********************************/ /* glass[a][b] */ /* a is bucket number */ /* b is glass color */ /* b = 1 Brown */ /* b = 2 Green */ /* b = 3 Clean */ /********************************/ int main(int argc, char* argv[]) { unsigned int Bucket[3][3]; int can_1, can_2, can_3; while (scanf("%d %d %d %d %d %d %d %d %d", &Bucket[0][0], &Bucket[0][1], &Bucket[0][2], &Bucket[1][0], &Bucket[1][1], &Bucket[1][2], &Bucket[2][0], &Bucket[2][1], &Bucket[2][2]) != EOF) { /* initiate */ unsigned int max = 0 , move = 0; int init = 0, total = 0, temp_total = 0; string s_goal = "XXX"; for(int i=0 ; i<3 ; i++) { for(int j=0 ; j<3 ; j++) { total = total + Bucket[i][j]; } } for(can_1=0 ; can_1<3 ; can_1++) { init = Bucket[0][can_1]; temp_total = Bucket[0][can_1]; for(can_2=0 ; can_2<3 ; can_2++) { if(can_1 != can_2) { temp_total = temp_total + Bucket[1][can_2]; for(can_3=0 ; can_3<3 ; can_3++) { if( (can_3 != can_2) && (can_3 != can_1) ) { temp_total = temp_total + Bucket[2][can_3]; if(temp_total >= max) { s_goal = funct(can_1 , can_2 , can_3 , s_goal , temp_total , max); max = temp_total; } temp_total = init; } } } } } move = total - max; cout<< s_goal << " " << move <<endl; } return 0; } string funct(int c1 , int c2 , int c3 , string s_temp , int temp , int temp_max) { string str=""; int size = 0; if(c1==0){ str=str+"B"; }else if(c1==1){ str=str+"G"; }else str=str+"C"; if(c2==0){ str=str+"B"; }else if(c2==1){ str=str+"G"; }else str=str+"C"; if(c3==0){ str=str+"B"; }else if(c3==1){ str=str+"G"; }else str=str+"C"; if(temp == temp_max) { while(size < 2) { if(str[size] < s_temp[size]) return str; else if(str[size] > s_temp[size]) break; else size++; } return s_temp; } return str; }
Wednesday, July 21, 2010
ACM-102 Ecological Bin Packing with C++
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment