Skip to content

Commit bd8f382

Browse files
Create CEOI 21-stones.cpp
1 parent fbf10f4 commit bd8f382

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

CEOI/CEOI 21-stones.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
CEOI 2021 Stones
3+
- Basically, you choose stones and piles so that Branko
4+
must always take 1 stone, and there is either an even
5+
number of single-stone piles when he has to pick from
6+
a pile or there's at least one pile with >1 stone.
7+
*/
8+
9+
#include <iostream>
10+
#include <set>
11+
using namespace std;
12+
13+
int a[501];
14+
15+
int main() {
16+
int n;
17+
cin >> n;
18+
set<int> ones, others;
19+
for (int i = 1; i <= n; i++) {
20+
cin >> a[i];
21+
if (a[i] == 1) ones.insert(i);
22+
else others.insert(i);
23+
}
24+
while (true) {
25+
int x;
26+
cin >> x;
27+
if (a[x] == 1) {
28+
ones.erase(x);
29+
cout << 1 << endl;
30+
if (ones.size() == 0 && others.size() == 0)
31+
return cout << -1 << endl, 0;
32+
cout << *ones.begin() << endl;
33+
ones.erase(ones.begin());
34+
cin >> x;
35+
} else {
36+
others.erase(x);
37+
if (others.size() == 0) {
38+
cout << a[x] << endl;
39+
if (ones.size() == 0)
40+
return cout << -1 << endl, 0;
41+
cout << *ones.begin() << endl;
42+
ones.erase(ones.begin());
43+
cin >> x;
44+
} else {
45+
cout << a[x] - 1 << endl << x << endl;
46+
cin >> x;
47+
}
48+
}
49+
}
50+
return 0;
51+
}

0 commit comments

Comments
 (0)