forked from ksaveljev/UVa-online-judge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10142.cpp
92 lines (70 loc) · 1.61 KB
/
10142.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
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(void) {
int n, tmp;
int cases;
string input;
map<int,string> candidates;
int votes[1001][21];
map<int,bool> eliminated;
cin >> cases;
while (cases--) {
cin >> n;
cin.ignore(100, '\n');
candidates.clear();
eliminated.clear();
for (int i = 1; i <= n; i++) {
getline(cin, input);
candidates[i] = input;
}
int cur = 0;
while (cin.peek() != '\n' && cin.peek() != -1) {
for (int i = 0; i < n; i++)
cin >> votes[cur][i];
cin.ignore(100, '\n');
cur++;
}
int best;
int count[21];
while (true) {
best = 0;
fill(count, count+21, 0);
for (int i = 0; i < cur; i++) {
for (int j = 0; j < n; j++) {
if (eliminated[votes[i][j]]) continue;
count[votes[i][j]]++;
if (count[votes[i][j]] > best)
best = count[votes[i][j]];
break;
}
}
if (best * 2 > cur)
break;
int lowest = best;
for (int i = 1; i <= n; i++) {
if (eliminated[i]) continue;
if (count[i] < lowest)
lowest = count[i];
}
if (lowest == best)
break;
for (int i = 1; i <= n; i++) {
if (eliminated[i]) continue;
if (count[i] == lowest)
eliminated[i] = true;
}
}
for (int i = 1; i <= n; i++) {
if (eliminated[i]) continue;
if (count[i] == best)
cout << candidates[i] << endl;
}
if (cases)
cout << endl;
}
return 0;
}