题解:P16441 [XJTUPC 2026] 直播获奖

· · 题解

::::info[思路]{open} 因为数据小,所以考虑模拟。 :::info[加入玩家]{open} 按 UID 加入玩家,已揭露的玩家按成绩从高到低用 sort 排序。 ::: :::info[确认 A 队]{open}

  1. 取出成绩前 5 名。
  2. 如果阴阳都有,那么 A=5 人。
  3. 如果全阴或者全阳,就取该种元素前 4,再加上另一元素成绩最高的 1 个。 ::: :::info[确认 B 队]{open}
  4. 按成绩从高到低遍历。
  5. 每个公会最多 5 人。
  6. 选到 12 人或全部遍历结束为止。 ::: :::info[输出]{open}
  7. 每步收集 A + B 队的 UID。
  8. A 队内按 UID 小到大输出,B 队一样,然后拼接。 ::: :::: ::::success[AC code]{open}
    
    #include <cstdio>
    #include <vector>
    #include <algorithm>
    #include <unordered_set>
    using namespace std;

struct P { int uid, ele, gid, sco; };

int main() { int n; scanf("%d", &n); vector<P> ps; for(int uid = 1; uid <= n; uid++){ int x, y, z; scanf("%d%d%d", &x, &y, &z); ps.push_back({uid, x, y, z}); vector<P> srt = ps; sort(srt.begin(), srt.end(), [](const P& a, const P& b) { return a.sco > b.sco; }); vector<int> A; if(srt.size() <= 4){ for (const auto& p : srt) A.push_back(p.uid); }else{ vector<P> top5(srt.begin(), srt.begin() + 5); bool hy = false, hg = false; for(const auto& p : top5){ if(p.ele == 0) hy = true; else hg = true; } if(hy && hg){ for(const auto& p : top5) A.push_back(p.uid); }else{ int xe = top5[0].ele; vector<P> bx; for (const auto& p : ps) if (p.ele == xe) bx.push_back(p); sort(bx.begin(), bx.end(), [](const P& a, const P& b) { return a.sco > b.sco; }); int tx = min(4, (int)bx.size()); for (int i = 0; i < tx; i++) A.push_back(bx[i].uid); int ye = 1 - xe; vector<P> by; for (const auto& p : ps) if (p.ele == ye) by.push_back(p); if (!by.empty()) { sort(by.begin(), by.end(), [](const P& a, const P& b) { return a.sco > b.sco; }); A.push_back(by[0].uid); } } } unordered_set<int> stA(A.begin(), A.end()); int cnt[105] = {0}; for (const auto& p : ps) if (stA.count(p.uid)) cnt[p.gid]++; vector<P> rst; for (const auto& p : ps) if (!stA.count(p.uid)) rst.push_back(p); sort(rst.begin(), rst.end(), [](const P& a, const P& b) { return a.sco > b.sco; }); vector<int> B; for(const auto& p : rst){ if(B.size() >= 12) break; if(cnt[p.gid] < 5){ B.push_back(p.uid); cnt[p.gid]++; } } sort(A.begin(), A.end()); sort(B.begin(), B.end()); for(size_t i = 0; i < A.size(); i++){ if(i) printf(" "); printf("%d", A[i]); } for(size_t i = 0; i < B.size(); i++) printf(" %d", B[i]); printf("\n"); } return 0; }


::::