fork download
  1. #include<cstdio>
  2. #include<algorithm>
  3. int can[3][3];
  4. int list[3];
  5. #define Brown 0
  6. #define Clear 2
  7. #define Green 1
  8.  
  9. int index_change(int x)
  10. {
  11. if(x==1)return 2;
  12. if(x==2)return 1;
  13. return 0;
  14. }
  15. int All;
  16. int GetMoveStep(int *ptr)
  17. {
  18. return All -can[0][index_change(ptr[0])]
  19. -can[1][index_change(ptr[1])]
  20. -can[2][index_change(ptr[2])];
  21. }
  22.  
  23. int main()
  24. {
  25. int ans,M,out[3];
  26. while(~scanf("%d%d%d%d%d%d%d%d%d", &can[0][0],&can[0][1],&can[0][2],
  27. &can[1][0],&can[1][1],&can[1][2],
  28. &can[2][0],&can[2][1],&can[2][2]))
  29. {
  30. All=0;
  31. for(int i=0;i<3;++i)
  32. for(int j=0;j<3;++j)
  33. All+=can[i][j];
  34. list[0]=0;
  35. list[1]=1;
  36. list[2]=2;
  37. ans=0x7fffffff;
  38. do{
  39. M=GetMoveStep(list);
  40. if(ans>M)
  41. {
  42. ans=M;
  43. out[0]=list[0];
  44. out[1]=list[1];
  45. out[2]=list[2];
  46. }
  47. }while(std::next_permutation(list,list+3));
  48. for(int i=0;i<3;++i)
  49. {
  50. if(out[i]==Brown)putchar('B');
  51. else if(out[i]==Clear)putchar('G');
  52. else putchar('C');
  53. }
  54. printf(" %d\n",ans);
  55. }
  56. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Standard output is empty