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

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

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

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

No Rounded CornersTailwind FirstDossier Ready
06-deliverables/appendix-code.md

红色据点方格图:纪念点热度区域统计 代码附录

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

文件类型Markdown

10-cases/s2-jh-05-checkpoint-grid/06-deliverables/appendix-code.md

Python 主实现

源文件:main.py

  • 实现状态:当前已有可执行实现
import sys


def solve(data: str) -> str:
    tokens = list(map(int, data.split()))
    if not tokens:
        return ""
    it = iter(tokens)
    rows = next(it)
    cols = next(it)
    queries = next(it)
    prefix = [[0] * (cols + 1) for _ in range(rows + 1)]
    for row in range(1, rows + 1):
        row_sum = 0
        for col in range(1, cols + 1):
            value = next(it)
            row_sum += value
            prefix[row][col] = prefix[row - 1][col] + row_sum
    answers = []
    best_query = 1
    best_sum = -1
    for query_id in range(1, queries + 1):
        r1 = next(it)
        c1 = next(it)
        r2 = next(it)
        c2 = next(it)
        total = prefix[r2][c2] - prefix[r1 - 1][c2] - prefix[r2][c1 - 1] + prefix[r1 - 1][c1 - 1]
        answers.append(str(total))
        if total > best_sum:
            best_sum = total
            best_query = query_id
    return f"results={' '.join(answers)}\nbest_query={best_query} {best_sum}"


if __name__ == "__main__":
    sys.stdout.write(solve(sys.stdin.read()).strip())
    sys.stdout.write("\n")

C++ 对照实现

源文件:main.cpp

  • 实现状态:当前已有可执行实现
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    int rows, cols, queries;
    if (!(cin >> rows >> cols >> queries)) {
        return 0;
    }
    vector<vector<long long>> prefix(rows + 1, vector<long long>(cols + 1, 0));
    for (int row = 1; row <= rows; ++row) {
        long long row_sum = 0;
        for (int col = 1; col <= cols; ++col) {
            long long value;
            cin >> value;
            row_sum += value;
            prefix[row][col] = prefix[row - 1][col] + row_sum;
        }
    }
    vector<long long> answers;
    int best_query = 1;
    long long best_sum = -1;
    for (int query_id = 1; query_id <= queries; ++query_id) {
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        long long total = prefix[r2][c2] - prefix[r1 - 1][c2] - prefix[r2][c1 - 1] + prefix[r1 - 1][c1 - 1];
        answers.push_back(total);
        if (total > best_sum) {
            best_sum = total;
            best_query = query_id;
        }
    }
    cout << "results=";
    for (size_t i = 0; i < answers.size(); ++i) {
        if (i) {
            cout << ' ';
        }
        cout << answers[i];
    }
    cout << "\n";
    cout << "best_query=" << best_query << ' ' << best_sum << "\n";
    return 0;
}