
声明:
叠甲:
leetcodeHard),因为不是真的找所以就写个名字,发出来主要是为了博看官一笑,希望不要做价值判断,非要做我也不介意但我大概率不会解释的const PRIORITY = [ {1, c => c.code.codeforces.rating >= 2000}, {2, c => leetcodeHard(c)}, {3, c => c.singing.lesMiserables.canSingAllTunes && c.isV2EXer}, {4, c => c.videoGame.theWitness.hasFullAchievements}, {5, c => c.body.hand.isPretty && willingHoldHands(c) && c.isV2EXer} ]; const COnDITIONS= [ c => isStudent(c), c => c.gender == male, c => c.major == "math" || "CS" || "EE", c => knowsLesMiserables(c) ]; const finalJudging = [ c => c.code.codeforces.rating, c => -c.education.schoolRank, c => -c.education.majorRank, c => c.singing.ability ] Candidate select(candidates) { vector<vector> priorityCandidates(4); for (c : candidates) { int x = 0; for (p : PRIORITY) { if (p.second(c)) { x = p.first; break; } } if (x == 1) { return c; // 不会吧不会吧不会真有 cf2000 吧 }else if (x > 0) { priorityCandidates[x-2].push_back(c); } } for (candidatesList : priorityCandidates) { Candidate result; int prev = 0; for (c : candidatesList) { int x = conditionsMetCount(c); if (x == 4) { return c; } if (x > prev) { prev = x; result = c; } } if (result) { return result; } } vector<Candidate> conditionCandidates; for (c : candidates) { bool meetAllCOnditions= true; for (con : conditions) { meetAllConditions &= con(c); } if (meetAllConditions) { conditionCandidates.push_back(c); } } if (conditionCandidates.empty()) { throw error("没有找到合适的人!"); } sort(conditionCandidates, (a, b) => { for (f : finalJudging) { if (f(a) != f(b)) { return f(a) > f(b); } } }); return conditionCandidates[0]; } try { Candidate chosen = select(candidates); // 因为 candidates 数组本身就是按时间顺序排序的,所以有几个默认返回前者的情况。 } catch () { cry(); } 注:
1 sangsang654321 OP 忘记怎么附言了!!! 重看了一遍感觉第一个数组标 12345 蠢蠢的,直接遍历然后读 index 会更优雅一点。 |
2 liu731 PRO 魔怔人,我不愿意非工作时间看代码 |
3 HUZHUANGZHUANG 264 天前 看到我眼前一黑,相亲就是把条件摆出来大家比一比,你还当个谜语人,祝好 |