V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sangsang654321
V2EX  ›  随想

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

  •  
  •   sangsang654321 · 2 天前 · 630 次点击

    声明:

    • 并不是真的找,只是感觉如果真的要送一张票找人陪我看(是的我确实有两张票(炫耀)),我会这样根据 XP 和实用性(?)来做决定。

    叠甲:

    • 代码水平不怎么样且玻璃心,如果觉得哪里有问题,希望能被指出问题而不是说我菜><说我菜我就哭(不是)
    • 有些函数的具体内涵不一定和命名完全吻合(对我说的就是你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();
    }
    

    注:

    • AI 参与命名与审阅(但很多有道理的我没改)
    • 感觉逻辑有点复杂可读性有点差,写伪代码就是为了一眼看过去就看明白怎么回事(顺便偷懒+掩盖自己很多地方会写错),但同时又需要很多判断逻辑处理各种情况……><
    3 条回复    2025-03-15 00:37:20 +08:00
    sangsang654321
        1
    sangsang654321  
    OP
       2 天前
    忘记怎么附言了!!!
    重看了一遍感觉第一个数组标 12345 蠢蠢的,直接遍历然后读 index 会更优雅一点。
    liu731
        2
    liu731  
       2 天前   ❤️ 1
    魔怔人,我不愿意非工作时间看代码
    HUZHUANGZHUANG
        3
    HUZHUANGZHUANG  
       2 天前
    看到我眼前一黑,相亲就是把条件摆出来大家比一比,你还当个谜语人,祝好
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3967 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 05:21 · PVG 13:21 · LAX 22:21 · JFK 01:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.