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
| #include<bits/stdc++.h> #define int long long #define endl "\n" using namespace std;
struct SUB{ string name, cond; int tihao, time; };
struct Team{ string name; vector<bool> befpas; vector<int> beftim; int befcnt; int fbqtim;
int totcnt; int tottime; Team(): befpas(26, false), beftim(26, 0), befcnt(0), fbqtim(0), totcnt(0),tottime(0) {} };
bool cmp(const SUB& p, const SUB& q){ return p.time < q.time; }
bool cmpshang(const Team& p ,const Team& q){ if(p.totcnt == q.totcnt){ return p.tottime < q.tottime; } return p.totcnt > q.totcnt; }
bool cmpxia(const Team& p ,const Team& q){ if(p.befcnt == q.befcnt){ return p.fbqtim < q.fbqtim; } return p.befcnt > q.befcnt; }
signed main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int T; cin >> T; while (T--) { int n; cin >> n; vector<SUB> v(n); vector<string> jigedui; unordered_map<string, int> mp; for (int i = 0; i < n; i++) { string team, res, pid; int t; cin >> team >> pid >> t >> res; SUB sub; int cnt = 0; sub.name = team; bool flag = false; if (mp.find(team) == mp.end()) { int idx = (int)jigedui.size(); jigedui.push_back(team); mp[team] = idx; } int x = pid[0] - 'A'; sub.tihao = x; sub.time = t; sub.cond = res; cnt++; v[i] = sub; } sort(v.begin(), v.end(), cmp); int duishu = jigedui.size(); vector<Team> dui(duishu); for (int i = 0; i < duishu; i++) { dui[i].name = jigedui[i]; } int tiaochu = n; for (int i = 0; i < n; i++) { if (v[i].time >= 240) { tiaochu = i; break; } string s = v[i].name; int tj = mp[v[i].name]; Team &t = dui[tj]; if (v[i].cond[0] == 'A' && t.befpas[v[i].tihao] == false) { t.totcnt++; t.befcnt++; t.befpas[v[i].tihao] = true; t.beftim[v[i].tihao] += v[i].time; t.fbqtim += t.beftim[v[i].tihao]; t.tottime += t.beftim[v[i].tihao]; } else if (v[i].cond[0] == 'R' && t.befpas[v[i].tihao] == false) { t.beftim[v[i].tihao] += 20; } dui[tj] = t; } for (int i = tiaochu; i < n; i++) { int tj = mp[v[i].name]; Team &t = dui[tj]; if (v[i].cond[0] == 'U' && t.befpas[v[i].tihao] == false) { t.totcnt++; t.befpas[v[i].tihao] = true; t.beftim[v[i].tihao] += v[i].time; t.tottime += t.beftim[v[i].tihao]; } else if (v[i].cond[0] == 'R' && t.befpas[v[i].tihao] == false) { t.beftim[v[i].tihao] += 20; } dui[tj] = t; } vector<Team> dui2 = dui; sort(dui.begin(), dui.end(), cmpshang); sort(dui2.begin(), dui2.end(), cmpxia); vector<string> re; int bestcnt = dui[0].totcnt; int besttime = dui[0].tottime; for (int i = 0; i < duishu; i++) { if (dui[i].totcnt > dui2[0].befcnt) { re.push_back(dui[i].name); } else if (dui[i].totcnt == dui2[0].befcnt && dui[i].tottime <= dui2[0].fbqtim) { re.push_back(dui[i].name); } else { break; } } sort(re.begin(), re.end()); for (int i = 0; i < re.size(); i++) { if (i) cout << " "; cout << re[i]; } cout << endl; } return 0; }
|