2013年10月9日 星期三

UVA 102 Ecological Bin Packing

[炸]
看背景介紹,原本以為是啥DP,原來只是硬炸XD



#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

long long int b1,g1,c1;
long long int b2,g2,c2;
long long int b3,g3,c3;
long long int cost(const char ch[4])
{
    long long int re=0;
    re+=(ch[0]=='B')*(b2+b3)+(ch[0]=='G')*(g2+g3)+(ch[0]=='C')*(c2+c3);
    re+=(ch[1]=='B')*(b1+b3)+(ch[1]=='G')*(g1+g3)+(ch[1]=='C')*(c1+c3);
    re+=(ch[2]=='B')*(b2+b1)+(ch[2]=='G')*(g2+g1)+(ch[2]=='C')*(c2+c1);
    return re;
}
int main()
{
    while(scanf("%I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d",&b1,&g1,&c1,&b2,&g2,&c2,&b3,&g3,&c3)!=EOF)
    {
        long long int cc=cost("GCB");
        char p[4]="GCB";
        if(cc>=cost("GBC")){cc=cost("GBC");strcpy(p,"GBC");}
        if(cc>=cost("CGB")){cc=cost("CGB");strcpy(p,"CGB");}
        if(cc>=cost("CBG")){cc=cost("CBG");strcpy(p,"CBG");}
        if(cc>=cost("BGC")){cc=cost("BGC");strcpy(p,"BGC");}
        if(cc>=cost("BCG")){cc=cost("BCG");strcpy(p,"BCG");}
        printf("%s %d\n",p,cc);
    }
    return 0;
}

沒有留言:

張貼留言