uva102 Ecological Bin Packing

/*
uva102 Ecological Bin Packing
AC by Warteac
2013-4-11
Runtime:0.148s
*/


#include<iostream>
#include<cstring>
using namespace std;
enum {B=0,G=1,C=2};
const int bcolor[6][3] = {{B,C,G},{B,G,C},{C,B,G},{C,G,B},{G,B,C},{G,C,B}};
const string color[6] = {"BCG","BGC","CBG","CGB","GBC","GCB"};
class EcoloBinPack{
private:
	int bin[3][3];
	int minMove;
	string rec;
public:
	void initial();
	bool readCase();
	void computing();
	void outResult();
};
void EcoloBinPack::initial(){
	memset(bin,0,sizeof(bin));
	rec = " ";
	minMove = 0;
}
bool EcoloBinPack::readCase(){	
	initial();
	if(cin >> bin[0][0] >> bin[0][1] >> bin[0][2] 
	   >> bin[1][0] >> bin[1][1] >> bin[1][2]
	   >> bin[2][0] >> bin[2][1] >> bin[2][2])
	return true;
	else return false;
}
void EcoloBinPack::computing(){
	int totalMove=0,temp;
	for(int i = 0; i < 3; i++)
	    for(int j = 0; j < 3; j++){
		totalMove += bin[i][j];
	}
	//cout<<"totalMove = "<<totalMove<<endl;
	minMove = totalMove;
	for(int x = 0; x < 6; x++){
		temp = totalMove - bin[0][bcolor[x][0]]
		     - bin[1][bcolor[x][1]] - bin[2][bcolor[x][2]];
		     //cout<<color[x][0]<<endl;
		     //cout<<bin[1][color[x][0]]<<endl;
		// cout << temp << endl;
		if(temp < minMove){
			minMove = temp;
			rec = color[x];
		}
	}
}
void EcoloBinPack::outResult(){
	cout << rec <<' '<<minMove<<endl;
}
int main(){
	EcoloBinPack ebp;
	while(ebp.readCase()){
		ebp.computing();
		ebp.outResult();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值