uva_102 - Ecological Bin Packing
[cpp]
/**本题是求最少移动次数,即比较第一个箱子中的相同颜色瓶子数量,不移动瓶子最多的那个,
*然后在剩余两个箱子中继续应用这个法则,最后得出总计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;
}
补充:软件开发 , C++ ,