三个杂色箱子分放不同色瓶子
#include <cstdio> #include <iostream> using namespace std; int main() { char ch[6][4]={"BCG","BGC","CBG","CGB","GBC","GCB"}; int temp[6][9] = { 0,1,1, 1,1,0, 1,0,1, 0,1,1, 1,0,1, 1,1,0, 1,1,0, 0,1,1, 1,0,1, 1,1,0, 1,0,1, 0,1,1, 1,0,1, 0,1,1, 1,1,0, 1,0,1, 1,1,0, 0,1,1 }; int a[9]; int min9; while(~scanf("%d",&a[0])) { min9 = a[0]; for(int i = 1; i < 9; i++) { scanf("%d",&a[i]); min9 +=a[i]; } int ans = min9; int ip=0; for(int i = 0; i < 6; i++) { ans = 0; for(int j = 0; j < 9; j++) { ans +=temp[i][j] * a[j]; } if(ans < min9) { min9 = ans; ip = i; } } printf("%s %d\n",ch[ip],min9); } return 0; }