World Robot Contest2025-2026Algorithm Application ThemeJunior Highwrc.hao.work
WRC
Contest Archive / Structured Dossiers青少年算法应用训练档案馆

把训练题、知识点、执行证据和最终解题档案统一归档成可直接浏览的竞赛资料库。

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

完整题面 / 题解 / 运行证据

No Rounded CornersTailwind FirstDossier Ready
03-execution/run-002/source-snapshot/main.cpp

main.cpp

站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。

文件类型.cpp

10-cases/s4-jh-04-resource-allocation/03-execution/run-002/source-snapshot/main.cpp

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct Team {
    int priority;
    int order;
    string name;
    int need_food;
    int need_med;
    int need_tools;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int food, med, tools, n;
    if (!(cin >> food >> med >> tools)) {
        return 0;
    }
    cin >> n;
    vector<Team> teams(n);
    for (int i = 0; i < n; ++i) {
        cin >> teams[i].name >> teams[i].priority >> teams[i].need_food >> teams[i].need_med >> teams[i].need_tools;
        teams[i].order = i;
    }
    sort(teams.begin(), teams.end(), [](const Team& left, const Team& right) {
        if (left.priority != right.priority) {
            return left.priority > right.priority;
        }
        return left.order < right.order;
    });
    vector<string> selected;
    for (const auto& team : teams) {
        if (team.need_food <= food && team.need_med <= med && team.need_tools <= tools) {
            food -= team.need_food;
            med -= team.need_med;
            tools -= team.need_tools;
            selected.push_back(team.name);
        }
    }
    cout << "selected=" << selected.size() << "\n";
    cout << "teams=";
    if (selected.empty()) {
        cout << "NONE";
    } else {
        for (size_t i = 0; i < selected.size(); ++i) {
            if (i) {
                cout << ',';
            }
            cout << selected[i];
        }
    }
    cout << "\n";
    cout << "remaining=" << food << ' ' << med << ' ' << tools << "\n";
    cout << "unserved=" << (n - static_cast<int>(selected.size())) << "\n";
    return 0;
}