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/s3-jh-03-tech-schedule/03-execution/run-002/source-snapshot/main.cpp

#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

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

    int n;
    if (!(cin >> n)) {
        return 0;
    }
    vector<string> names(n + 1);
    vector<long long> duration(n + 1, 0), start(n + 1, 0), finish(n + 1, 0);
    vector<int> indegree(n + 1, 0);
    vector<vector<int>> graph(n + 1);
    for (int task = 1; task <= n; ++task) {
        int k;
        cin >> names[task] >> duration[task] >> k;
        for (int i = 0; i < k; ++i) {
            int pre;
            cin >> pre;
            graph[pre].push_back(task);
            ++indegree[task];
        }
    }
    priority_queue<int, vector<int>, greater<int>> pq;
    for (int task = 1; task <= n; ++task) {
        if (indegree[task] == 0) {
            pq.push(task);
        }
    }
    int processed = 0;
    while (!pq.empty()) {
        int task = pq.top();
        pq.pop();
        ++processed;
        finish[task] = start[task] + duration[task];
        for (int nxt : graph[task]) {
            if (finish[task] > start[nxt]) {
                start[nxt] = finish[task];
            }
            --indegree[nxt];
            if (indegree[nxt] == 0) {
                pq.push(nxt);
            }
        }
    }
    if (processed != n) {
        cout << "total_days=-1\n";
        cout << "schedule=INVALID\n";
        return 0;
    }
    long long total_days = 0;
    for (int i = 1; i <= n; ++i) {
        if (finish[i] > total_days) {
            total_days = finish[i];
        }
    }
    cout << "total_days=" << total_days << "\n";
    cout << "schedule=";
    for (int i = 1; i <= n; ++i) {
        if (i > 1) {
            cout << '|';
        }
        cout << names[i] << ':' << start[i] << '-' << finish[i];
    }
    cout << "\n";
    return 0;
}