#include #include #include using namespace std; #define INF -10000 class Contestant { public: string name; string sex; int round1; int round2; double round11; double round22; double lastCore; Contestant() {} Contestant(string n, string s, int r1, int r2) { name = n; sex = s; round1 = r1; round2 = r2; } }; bool cmp(Contestant e1, Contestant e2) { return e1.lastCore > e2.lastCore; } class Joiner { Contestant *c; int n; int index; int x1; int x2; public: Joiner(int k) { n = k; x1 = INF; x2 = INF; index = 0; c = new Contestant[n + 1]; } void add(Contestant e) { index++; if (e.round1 > x1) x1 = e.round1; if (e.round2 > x2) x2 = e.round2; c[index] = e; } void work() {//计算相对成绩 for (int i = 1; i <= n; i++) { c[i].round11 = c[i].round1 * (300.0 / x1); c[i].round22 = c[i].round2 * (300.0 / x2); } } Contestant* getC() { return c; } }; class Proteam { Contestant *c; Contestant *p; int n; int m; int index; int flag; public: Proteam(Contestant *e, int k, int t) { c = e; index = 0; n = k; m = t; p = new Contestant[m + 1]; flag = 0; } void work() {//计算总成绩 for (int i = 1; i <= n; i++) { c[i].lastCore = c[i].round11 * 0.3 + c[i].round22 * 0.7; } sort(c + 1, c + n + 1, cmp); for (int i = 1; i <= n; i++) if (c[i].sex == "female") { p[++index] = c[i]; flag = i; break; } for (int i = 1; i <= n; i++) { if (flag == i) continue; index++; if (index <= m) p[index] = c[i]; else break; } sort(p + 1, p + m + 1, cmp); } void print() { printf("The member list of Shandong team is as follows:\n"); for (int i = 1; i <= m; i++) cout << p[i].name << endl; } }; void run() { int n, m; string name; string sex; int round1; int round2; cin >> n >> m; Joiner j(n); for (int i = 1; i <= n; i++) { cin >> name >> sex >> round1 >> round2; j.add(Contestant(name, sex, round1, round2)); } j.work(); Proteam p(j.getC(), n, m); p.work(); p.print(); } int main() { int T; cin >> T; while (T--) { run(); } }