您的位置:首页 > 其它

uva102 Ecological Bin Packing

2013-04-13 02:22 274 查看
/*
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: