突发奇想将自己的要求写成了伪代码形式,感觉程序猿相亲或者找游戏搭子()是不是可以参考这种思路

4 天前
 sangsang654321

声明:

叠甲:

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();
}

注:

676 次点击
所在节点    随想
3 条回复
sangsang654321
4 天前
忘记怎么附言了!!!
重看了一遍感觉第一个数组标 12345 蠢蠢的,直接遍历然后读 index 会更优雅一点。
liu731
4 天前
魔怔人,我不愿意非工作时间看代码
HUZHUANGZHUANG
3 天前
看到我眼前一黑,相亲就是把条件摆出来大家比一比,你还当个谜语人,祝好

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1118469

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX