forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoosball.cpp
142 lines (119 loc) · 3.16 KB
/
foosball.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <unordered_map>
#include <iostream>
#include <queue>
using namespace std;
struct dyn {
string n1;
string n2;
int w;
};
int main() {
int n;
cin >> n;
// Read in input
queue<string> names;
vector<string> allnames;
for(int i = 0; i < n; i++) {
string temp;
cin >> temp;
names.push(temp);
allnames.push_back(temp);
}
string results;
cin >> results;
// Setup
string w1, w2, b1, b2;
w1 = names.front();
names.pop();
b1 = names.front();
names.pop();
w2 = names.front();
names.pop();
b2 = names.front();
names.pop();
unordered_map<string, vector<int>> timeplaying;
for(auto i : allnames) {
vector<int> v = {0};
timeplaying[i] = v;
}
// Store winners of each game
vector<dyn> winners;
char prev = 'A';
// Simulate
for(auto i : results) {
// Set all winstreaks to 0
for(auto i : allnames) {
timeplaying[i].push_back(0);
}
timeplaying[w1].pop_back();
timeplaying[w2].pop_back();
timeplaying[b1].pop_back();
timeplaying[b2].pop_back();
timeplaying[w1].push_back(timeplaying[w1].back()+1);
timeplaying[w2].push_back(timeplaying[w2].back()+1);
timeplaying[b1].push_back(timeplaying[b1].back()+1);
timeplaying[b2].push_back(timeplaying[b2].back()+1);
dyn win;
if(i == prev) {
win.w = winners[winners.size()-1].w + 1;
}
else {
win.w = 1;
}
if(i == 'W') {
win.n1 = w1;
win.n2 = w2;
swap(w1, w2);
names.push(b2);
b2 = b1;
b1 = names.front();
names.pop();
prev = 'W';
}
if(i == 'B') {
win.n1 = b1;
win.n2 = b2;
swap(b1, b2);
names.push(w2);
w2 = w1;
w1 = names.front();
names.pop();
prev = 'B';
}
/*
// Set all winstreaks to 0
for(auto i : allnames) {
timeplaying[i].push_back(0);
}
timeplaying[w1].pop_back();
timeplaying[w2].pop_back();
timeplaying[b1].pop_back();
timeplaying[b2].pop_back();
timeplaying[w1].push_back(timeplaying[w1].back()+1);
timeplaying[w2].push_back(timeplaying[w2].back()+1);
timeplaying[b1].push_back(timeplaying[b1].back()+1);
timeplaying[b2].push_back(timeplaying[b2].back()+1);
*/
winners.push_back(win);
}
// Find max
int best = 0;
for(auto i : winners) {
best = max(best, i.w);
}
// Print results
for(int i = 0; i < winners.size(); i++) {
if(winners[i].w == best) {
string winner1 = winners[i-best+1].n1 ;
string winner2 = winners[i-best+1].n2 ;
int t1 = timeplaying[winner1][i];
int t2 = timeplaying[winner2][i];
if(t1 >= t2) {
cout << winner1 << " " << winner2 << endl;
}
else {
cout << winner2 << " " << winner1 << endl;
}
}
}
}