-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathEven-Odd_Game.cpp
113 lines (98 loc) · 2.84 KB
/
Even-Odd_Game.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<bits/stdc++.h>
using namespace std;
const int MAX = 200005;
int n;
vector<int> a;
vector<int> a_odd;
vector<int> a_even;
int score_Alice;
int score_Bob;
bool turn; // turn = 1 : Alice first, turn = 0 : Bob first
int cnt = 0;
void input(){
score_Alice = 0, score_Bob = 0;
if(cnt % 2 == 0) turn = true; // Alice first
else turn = false;
cin >> n;
a.erase(a.begin(), a.end());
for(int i=0; i<n; i++){
int tmp;
cin >> tmp;
a.push_back(tmp);
}
a_odd.erase(a_odd.begin(), a_odd.end());
a_even.erase(a_even.begin(), a_even.end());
for(int i=0; i<n; i++){
if(a[i] % 2 == 0){
a_even.push_back(a[i]);
} else {
a_odd.push_back(a[i]);
}
}
sort(a_odd.begin(), a_odd.end(), [] (int a, int b){
return a > b;
});
sort(a_even.begin(), a_even.end(), [] (int a, int b){
return a > b;
});
}
int solve(){
while(!a_odd.empty() || !a_even.empty()){
if(turn){
// Alice first
if(!a_even.empty()){
score_Alice += a_even.front(); //cout << "Alice : " << a_even.front() << endl;
a_even.erase(a_even.begin(), a_even.begin() + 1);
} else {
if(!a_odd.empty()){
a_odd.erase(a_odd.begin(), a_odd.begin() + 1);
}
}
// Bob next
if(!a_odd.empty()){
score_Bob += a_odd.front(); //cout << "Bob : " << a_odd.front() << endl;
a_odd.erase(a_odd.begin(), a_odd.begin() + 1);
} else {
if(!a_even.empty()){
a_even.erase(a_even.begin(), a_even.begin() + 1);
}
}
} else {
// Bob first
if(!a_odd.empty()){
score_Bob += a_odd.front(); cout << "Bob : " << a_odd.front() << endl;
a_odd.erase(a_odd.begin(), a_odd.begin() + 1);
} else {
if(!a_even.empty()){
a_even.erase(a_even.begin(), a_even.begin() + 1);
}
}
// Alice next
if(!a_even.empty()){
score_Alice += a_even.front(); cout << "Alice : " << a_even.front() << endl;
a_even.erase(a_even.begin(), a_even.begin() + 1);
} else {
if(!a_odd.empty()){
a_odd.erase(a_odd.begin(), a_odd.begin() + 1);
}
}
}
}
if(score_Alice > score_Bob) return 1;
if(score_Alice == score_Bob) return 0;
return -1;
}
int main(){
int T;
cin >> T;
while(T > 0){
input();
int res = solve();
if(res == 1) cout << "Alice\n";
else if(res == -1) cout << "Bob\n";
else cout << "Tie\n";
cnt++;
T--;
}
return 0;
}