More actions
imported>Unknown No edit summary |
(Repair batch-0002 pages from live compare) |
||
| Line 10: | Line 10: | ||
void main() | void main() | ||
{ | { | ||
int bottle | int bottle[9]; // 입력되는 병 | ||
int nMove | int nMove[6]; // 이동 수 | ||
int i; | int i; | ||
char * bin | char * bin[6] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"}; | ||
int min; | int min; | ||
int index; | int index; | ||
| Line 22: | Line 22: | ||
for (i=0; i<9; i++) | for (i=0; i<9; i++) | ||
{ | { | ||
if (!(cin >> bottle | if (!(cin >> bottle[i])) | ||
{ | { | ||
isRight = false; | isRight = false; | ||
| Line 31: | Line 31: | ||
break; | break; | ||
nMove | nMove[1] = bottle[3]+bottle[6]+bottle[1]+bottle[7]+bottle[2]+bottle[5]; | ||
nMove | nMove[0] = bottle[3]+bottle[6]+bottle[2]+bottle[8]+bottle[1]+bottle[4]; | ||
nMove | nMove[4] = bottle[4]+bottle[7]+bottle[0]+bottle[6]+bottle[2]+bottle[5]; | ||
nMove | nMove[5] = bottle[4]+bottle[7]+bottle[2]+bottle[8]+bottle[0]+bottle[3]; | ||
nMove | nMove[2] = bottle[5]+bottle[8]+bottle[0]+bottle[6]+bottle[1]+bottle[4]; | ||
nMove | nMove[3] = bottle[5]+bottle[8]+bottle[1]+bottle[7]+bottle[0]+bottle[3]; | ||
min = nMove | min = nMove[0]; | ||
index = 0; | index = 0; | ||
for (i=1; i<6; i++) | for (i=1; i<6; i++) | ||
{ | { | ||
if (min > nMove | if (min > nMove[i]) | ||
{ | { | ||
min = nMove | min = nMove[i]; | ||
index = i; | index = i; | ||
} | } | ||
} | } | ||
cout << bin | cout << bin[index] << " " << nMove[index] << endl; | ||
} | } | ||
} | } | ||
---- | ---- | ||
EcologicalBinPacking [[문보창]] | |||
Latest revision as of 00:16, 27 March 2026
소감
2005/02/18 Accepted 0:00.293 436 모든 경우의 수를 일일이 세지 않고 풀수 있는 방법은 없을까?
코드
// no 102 - Ecological Bin Packing
#include <iostream>
using namespace std;
void main()
{
int bottle[9]; // 입력되는 병
int nMove[6]; // 이동 수
int i;
char * bin[6] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
int min;
int index;
bool isRight;
while (true)
{
isRight = true;
for (i=0; i<9; i++)
{
if (!(cin >> bottle[i]))
{
isRight = false;
break;
}
}
if (!isRight)
break;
nMove[1] = bottle[3]+bottle[6]+bottle[1]+bottle[7]+bottle[2]+bottle[5];
nMove[0] = bottle[3]+bottle[6]+bottle[2]+bottle[8]+bottle[1]+bottle[4];
nMove[4] = bottle[4]+bottle[7]+bottle[0]+bottle[6]+bottle[2]+bottle[5];
nMove[5] = bottle[4]+bottle[7]+bottle[2]+bottle[8]+bottle[0]+bottle[3];
nMove[2] = bottle[5]+bottle[8]+bottle[0]+bottle[6]+bottle[1]+bottle[4];
nMove[3] = bottle[5]+bottle[8]+bottle[1]+bottle[7]+bottle[0]+bottle[3];
min = nMove[0];
index = 0;
for (i=1; i<6; i++)
{
if (min > nMove[i])
{
min = nMove[i];
index = i;
}
}
cout << bin[index] << " " << nMove[index] << endl;
}
}
EcologicalBinPacking 문보창