forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ.cpp
More file actions
75 lines (65 loc) · 1.51 KB
/
J.cpp
File metadata and controls
75 lines (65 loc) · 1.51 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
int n, a[22];
deque<char> supply[22], discard[22];
void grab(int x, int y, int move)
{
if (a[y] < a[x])
swap(x, y);
while (!discard[y].empty())
{
supply[y].push_back(discard[y].back());
discard[y].pop_back();
}
while (!discard[x].empty())
{
supply[y].push_back(discard[x].back());
discard[x].pop_back();
}
if (supply[x].empty())
{
cout << "Player " << x + 1 << " wins after " << move << " moves." << endl;
exit(0);
}
}
int main()
{
freopen("jungle.in", "r", stdin);
freopen("jungle.out", "w", stdout);
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++)
{
string s;
cin >> s;
for (char c : s)
supply[i].push_back(c);
}
for (int move = 1, player = 0; move <= 1000000; move++)
{
char card = supply[player].front();
supply[player].pop_front();
discard[player].push_back(card);
for (int i = 0; i < n; i++)
if (i != player && !discard[i].empty() && discard[i].back() == card)
{
grab(i, player, move);
break;
}
int found = 0;
for (int i = 1; i <= n; i++)
if (!supply[(player + i) % n].empty())
{
found = 1;
player = (player + i) % n;
break;
}
if (!found)
{
cout << "Draw after " << move << " moves." << endl;
return 0;
}
}
cout << "Abandoned after 1000000 moves." << endl;
}