No older revisions available
No older revisions available
EcologicalBinPacking ¶
~cpp
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void input();
void findMinCount();
bool isMinValue(int aSum, int aMinValue);
void output(int colorResult, int min);
int bottle[9] = {0,};
string color[6] = {"BCG", "BGC", "GBC", "GCB", "CBG", "CGB"};
int colorIndex[6][3] = {{0,5,7}, {0,4,8}, {1,3,8}, {1,5,6}, {2,3,7}, {2,4,6}};
int main()
{
input();
findMinCount();
return 0;
}
void input()
{
int sum = 0;
for(int i = 0; i < 9; i++)
{
cin >> bottle[i];
sum += bottle[i];
if (sum > pow(2, 30))
{
cout << "병의 수 초과" << endl;
cout << "다시 입력" << endl;
sum = 0;
i = -1;
continue;
}
}
}
void findMinCount()
{
int sum = 0;
int minValue = 0;
int index = 0;
int colorResult = 0;
int allColorSet = 0;
while(allColorSet < 6)
{
for(int i = 0; i < 9; i++)
if (i == colorIndex[allColorSet][index] || i == colorIndex[allColorSet][index+1]
|| i == colorIndex[allColorSet][index+2])
continue;
else
sum += bottle[i];
if (allColorSet == 0)
minValue = sum;
if (isMinValue(sum, minValue))
{
minValue = sum;
colorResult = allColorSet;
}
allColorSet++;
sum = 0;
}
output(colorResult, minValue);
}
bool isMinValue(int aSum, int aMinValue)
{
return (aSum < aMinValue) ? true : false;
}
void output(int colorResult, int min)
{
cout << color[colorResult] << " " << min << endl;
}