-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path102.cpp
More file actions
54 lines (42 loc) · 1.13 KB
/
102.cpp
File metadata and controls
54 lines (42 loc) · 1.13 KB
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
#include <iostream>
#include <cstdint>
#include <string>
using namespace std;
int64_t bottles[9];
int64_t moves[6];
int64_t minMoves;
string output;
const string combinations[6] = {"BCG", "BGC", "CBG", "CGB", "GBC", "GCB"};
void solve();
int64_t countMoves(int64_t a, int64_t b, int64_t c);
int main() {
while (cin >> bottles[0] >> bottles[1] >> bottles[2] >> bottles[3] >> bottles[4] >> bottles[5] >> bottles[6] >> bottles[7] >> bottles[8]) {
solve();
}
return 0;
}
void solve() {
moves[0] = countMoves(0, 5, 7); // BCG
moves[1] = countMoves(0, 4, 8); // BGC
moves[2] = countMoves(2, 3, 7); // CBG
moves[3] = countMoves(2, 4, 6); // CGB
moves[4] = countMoves(1, 3, 8); // GBC
moves[5] = countMoves(1, 5, 6); // GCB
minMoves = moves[0];
output = combinations[0];
for (int64_t i = 1; i < 6; i++) {
if (moves[i] < minMoves) {
minMoves = moves[i];
output = combinations[i];
}
}
cout << output << ' ' << minMoves << endl;
}
int64_t countMoves(int64_t a, int64_t b, int64_t c) {
int64_t numMoves = 0;
for (int64_t i = 0; i < 9; i++) {
if ((i != a) && (i != b) && (i != c))
numMoves += bottles[i];
}
return numMoves;
}