Sunday, 13 May 2012

UVa 102 Ecological Bin Packing Solution

#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<cctype>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<fstream>
#include<cstdlib>
#include<vector>
#include<map>
#include<utility>
#include<iomanip>

using namespace std;
int main()
{
int b1,g1,c1,b2,g2,c2,b3,g3,c3,i,a[6],min;
while(cin>>b1>>g1>>c1>>b2>>g2>>c2>>b3>>g3>>c3)
    {
    a[0]=b2+b3+c1+c3+g1+g2;
    a[1]=b2+b3+c1+c2+g1+g3;
    a[2]=b1+b3+c2+c3+g1+g2;
    a[3]=b1+b2+c2+c3+g1+g3;
    a[4]=b1+b3+c1+c2+g3+g2;
    a[5]=b2+b1+c1+c3+g3+g2;
    for(i=0;i<6;i++)
        {
        if(i==0) min=a[i];
        else if(min>a[i]) min=a[i];
        }
    for(i=0;i<6;i++)
        {
        if(a[i]==min) {
                      if(i==0) cout<<"BCG ";
                      else if(i==1) cout<<"BGC ";
                      else if(i==2) cout<<"CBG ";
                      else if(i==3) cout<<"CGB ";
                      else if(i==4) cout<<"GBC ";
                      else if(i==5) cout<<"GCB ";
                      cout<<a[i]<<endl;
                      break;
                      }
        }
    }
return 0;
}

1 comment:

  1. #include
    int main()
    {
    int b1,g1,c1, b2,g2,c2, b3,g3,c3, i,cng_info[6],small_value,f;

    while(scanf("%d%d%d%d%d%d%d%d%d",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3) != EOF)
    {
    /*alphabetical sequence*/

    cng_info[0] = b2+b3+c1+c3+g1+g2; /* BCG */
    cng_info[1] = b2+b3+g1+g3+c1+c2; /* BGC */


    cng_info[2] = c2+c3+b1+b3+g1+g2; /* CBG */
    cng_info[3] = c2+c3+g1+g3+b1+b2; /* CGB */

    cng_info[4] = g2+g3+b1+b3+c1+c2; /* GBC */
    cng_info[5] = g2+g3+c1+c3+b1+b2; /* GCB */



    small_value = cng_info[0];
    f = 0;
    for(i=1; i<6; i++)
    if(small_value>cng_info[i])
    {
    small_value = cng_info[i];
    f = i;
    }


    if(f==0)
    printf("BCG ");
    else if(f==1)
    printf("BGC ");
    else if(f==2)
    printf("CBG ");
    else if(f==3)
    printf("CGB ");
    else if(f==4)
    printf("GBC ");
    else
    printf("GCB ");

    printf("%d\n",small_value);
    }


    return 0;
    }

    ReplyDelete