Advertisement
Go-Ice

UVa [102 - Ecological Bin Packing] by Go-Ice

Oct 25th, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. /*
  2.     Author: LinChuWen
  3.     Date: 2014/10/12
  4.     UVa Online Judge Problem #102 - Ecological Bin Packing
  5.     Description: http://uva.onlinejudge.org/external/1/102.pdf
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. int main(){
  12.     int b1,g1,c1,b2,g2,c2,b3,g3,c3;
  13.     long long int b1_sum,g1_sum,c1_sum,b2_sum,g2_sum,c2_sum,b3_sum,g3_sum,c3_sum;
  14.     long long int total[6],min;
  15.     int cnt,index;
  16.    
  17.     while(scanf("%d %d %d %d %d %d %d %d %d",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3)==9){
  18.         b1_sum=b2+b3;g1_sum=g2+g3;c1_sum=c2+c3;
  19.         b2_sum=b1+b3;g2_sum=g1+g3;c2_sum=c1+c3;
  20.         b3_sum=b1+b2;g3_sum=g1+g2;c3_sum=c1+c2;
  21.        
  22.         total[0]=b1_sum+c2_sum+g3_sum;
  23.         total[1]=b1_sum+g2_sum+c3_sum;
  24.         total[2]=c1_sum+b2_sum+g3_sum;
  25.         total[3]=c1_sum+g2_sum+b3_sum;
  26.         total[4]=g1_sum+b2_sum+c3_sum;
  27.         total[5]=g1_sum+c2_sum+b3_sum;
  28.        
  29.         index=0;
  30.         min=total[0];
  31.         for(cnt=1;cnt<6;cnt++){
  32.             if(total[cnt]<min){
  33.                 min=total[cnt];
  34.                 index=cnt;
  35.             } /* if end */
  36.         } /* for end */
  37.        
  38.         switch(index){
  39.             case 0:
  40.                 printf("BCG %lld\n",total[0]);
  41.                 break;
  42.             case 1:
  43.                 printf("BGC %lld\n",total[1]);
  44.                 break;
  45.             case 2:
  46.                 printf("CBG %lld\n",total[2]);
  47.                 break;
  48.             case 3:
  49.                 printf("CGB %lld\n",total[3]);
  50.                 break;
  51.             case 4:
  52.                 printf("GBC %lld\n",total[4]);
  53.                 break;
  54.             case 5:
  55.                 printf("GCB %lld\n",total[5]);
  56.                 break;
  57.         } /* switch end */
  58.     } /* big  while end */
  59.    
  60.     system("PAUSE");
  61.     return 0;
  62. } /* main end */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement