forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasketball_game.cpp
More file actions
78 lines (66 loc) · 1.62 KB
/
basketball_game.cpp
File metadata and controls
78 lines (66 loc) · 1.62 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
76
77
78
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
class player {
public:
string name;
int p, h, t;
bool operator<(const player& rhs) const {
if (p != rhs.p) return p > rhs.p;
return h > rhs.h;
}
}mm[30];
int N, M, P;
void doit(vector<int>& a, vector<int>& b) {
if (b.empty()) return;
REP(r,M) {
REP(i,P) ++mm[a[i]].t;
int idx1 = 0;
FOR(j,1,P-1) {
if (mm[a[j]].t > mm[a[idx1]].t || (mm[a[j]].t == mm[a[idx1]].t && a[j] > a[idx1])) idx1 = j;
}
int idx2 = 0;
FOR(j,1,b.size()-1) {
if (mm[b[j]].t < mm[b[idx2]].t || (mm[b[j]].t == mm[b[idx2]].t && b[j] < b[idx2])) idx2 = j;
}
swap(a[idx1], b[idx2]);
}
}
void run() {
cin >> N >> M >> P;
REP(i,N) {
cin >> mm[i].name >> mm[i].p >> mm[i].h;
mm[i].t = 0;
}
sort(mm, mm + N);
vector<string> ret;
vector<int> a, b;
REP(i,P) a.push_back(i * 2);
for (int i = P * 2; i < N; i += 2) b.push_back(i);
doit(a, b);
REP(i,P) ret.push_back(mm[a[i]].name);
a.clear();
b.clear();
REP(i,P) a.push_back(i * 2 + 1);
for (int i = P * 2 + 1; i < N; i += 2) b.push_back(i);
doit(a, b);
REP(i,P) ret.push_back(mm[a[i]].name);
sort(ret.begin(), ret.end());
REP(i,ret.size()) {
if (i) cout << " ";
cout << ret[i];
}
cout << endl;
}
int main() {
int T;
cin >> T;
FOR(t,1,T) {
cout << "Case #" << t << ": ";
run();
}
return 0;
}