forked from Diusrex/UVA-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
102 Ecological Bin Packing.cpp
58 lines (44 loc) · 1.47 KB
/
102 Ecological Bin Packing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int first, second, third;
while (cin >> first)
{
vector<vector<int> > bins(3, vector<int>(3));
for (int i = 0; i < 3; ++i)
{
cin >> third >> second;
bins[i][0] = first;
bins[i][1] = second;
bins[i][2] = third;
if (i != 2)
cin >> first;
}
vector<char> conversions(3);
conversions[0] = 'B'; conversions[1] = 'C'; conversions[2] = 'G';
vector<int> order(3);
order[0] = 0; order[1] = 1; order[2] = 2;
long lowestTotal = -1;
vector<int> bestArrangement;
do {
long currentTotal(0);
for (int i = 0; i < 3; ++i)
{
for (int b = 0; b < 3; ++b)
{
if (b != order[i])
currentTotal += bins[i][b];
}
}
if (currentTotal < lowestTotal || lowestTotal == -1)
{
lowestTotal = currentTotal;
bestArrangement = order;
}
} while (next_permutation(order.begin(), order.end()));
cout << conversions[bestArrangement[0]] << conversions[bestArrangement[1]] << conversions[bestArrangement[2]] << ' ' << lowestTotal << '\n';
}
}