소감


소스

~cpp 
#include <iostream>
using namespace std;

#define BROWN 0
#define GREEN 1
#define CLEAR 2

int main()
{
	while (true)
	{
	int bottle[3][3];	// 병
	int bin[3];			// 통
	int min_move = 0;	// 최소 이동수 = 전체 병 수 - 이동하지 않는 병 수
	int total_bottle = 0;
	int not_move_bottle = 0;
	int i, j;

	for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
		{
			if (!(cin >> bottle[i][j]))
				return 0;
			total_bottle += bottle[i][j];
		}

	bin[0] = BROWN;
	bin[1] = CLEAR;
	bin[2] = GREEN;
	not_move_bottle = bottle[0][BROWN] + bottle[1][CLEAR] + bottle[2][GREEN];

	if ((bottle[0][BROWN] + bottle[1][GREEN] + bottle[2][CLEAR]) > not_move_bottle)
	{
		bin[0] = BROWN;
		bin[1] = GREEN;
		bin[2] = CLEAR;
		not_move_bottle = bottle[0][BROWN] + bottle[1][GREEN] + bottle[2][CLEAR];
	}
	if ((bottle[0][CLEAR] + bottle[1][BROWN] + bottle[2][GREEN]) > not_move_bottle)
	{
		bin[0] = CLEAR;
		bin[1] = BROWN;
		bin[2] = GREEN;
		not_move_bottle = bottle[0][CLEAR] + bottle[1][BROWN] + bottle[2][GREEN];
	}
	if ((bottle[0][CLEAR] + bottle[1][GREEN] + bottle[2][BROWN]) > not_move_bottle)
	{
		bin[0] = CLEAR;
		bin[1] = GREEN;
		bin[2] = BROWN;
		not_move_bottle = bottle[0][CLEAR] + bottle[1][GREEN] + bottle[2][BROWN];
	}
	if ((bottle[0][GREEN] + bottle[1][BROWN] + bottle[2][CLEAR]) > not_move_bottle)
	{
		bin[0] = GREEN;
		bin[1] = BROWN;
		bin[2] = CLEAR;
		not_move_bottle = bottle[0][GREEN] + bottle[1][BROWN] + bottle[2][CLEAR];
	}
	if ((bottle[0][GREEN] + bottle[1][CLEAR] + bottle[2][BROWN]) > not_move_bottle)
	{
		bin[0] = GREEN;
		bin[1] = CLEAR;
		bin[2] = BROWN;
		not_move_bottle = bottle[0][GREEN] + bottle[1][CLEAR] + bottle[2][BROWN];
	}

	min_move = total_bottle - not_move_bottle;	

	for (i = 0; i < 3; i++)
	{
		if (bin[i] == BROWN)
			cout << "B";
		else if (bin[i] == CLEAR)
			cout << "C";
		else
			cout << "G";
	}
	cout << " " << min_move << endl;
	}
}

댓글

Retrieved from http://wiki.zeropage.org/wiki.php/EcologicalBinPacking/곽세환
last modified 2021-02-07 05:23:10