uva_102 - Ecological Bin Packing

/**本题是求最少移动次数,即比较第一个箱子中的相同颜色瓶子数量,不移动瓶子最多的那个,
  *然后在剩余两个箱子中继续应用这个法则,最后得出总计6种移动顺序,
  *将6种情况的序列和最终箱子分别存放瓶子的颜色字符串定义为结构体并列举出来,
  *然后算出移动次数最少和颜色字符串的字典序最小的情况
 */
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

#define NUM 9
#define WAY 6
#define MAX 11
#define INF 0x7fffffff

int arr[MAX];

struct way{
    int a, b, c;
    string color;
}way[]={
    {1,5,9,"BGC"},{1,8,6,"BCG"},{4,2,9,"GBC"},
    {4,8,3,"CBG"},{7,2,6,"GCB"},{7,5,3,"CGB"}
};

int main(){
    int maxv, count, sum;
    string str;
    while(~scanf("%d",&arr[1])){
        maxv = -INF;
        count = arr[1];
        for(int i=2; i<=NUM; i++){
            scanf("%d",&arr[i]);
            count += arr[i];
        }

        for(int i=0; i<WAY; i++){
            sum = arr[way[i].a]+arr[way[i].b]+arr[way[i].c];

            if(maxv < sum){maxv = sum; str = way[i].color;}
            else if(maxv==sum && str > way[i].color) str = way[i].color;
        }
        cout<<str<<' '<<count-maxv<<endl;
    }
    return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值