数据生成与检验 / Data generation and validation¶
使用 Python 3.10+ 标准库和 C++17 编译器,在题目目录执行下列命令。每个输入只有一个城镇,10个正式文件各占10%。
Use the Python 3.10+ standard library and a C++17 compiler. Run these commands from the problem directory. Each input contains one town; each of the 10 formal files is worth 10%.
g++ -std=c++17 -O2 -Wall -Wextra std.cpp -o std
python tests/generate.py --out-dir ../../../build/data/town-editing-simoleons-5 --std ./std
python tests/validate.py ../../../build/data/town-editing-simoleons-5/01.in
Windows 可传入 .exe 路径。省略 --std 只写入输入文件;生成器仍计算期望答案用于自检准备。--plan 指定计划,重复 --case 01 --case 02 选择文件,未知编号会报错。输出统一为UTF-8和LF换行。
Windows users can supply an .exe path. Without --std, only input files are written, though expected answers are still computed. Use --plan for another plan and repeat --case 01 --case 02 to select cases. Unknown IDs are rejected. Files use UTF-8 and LF.
覆盖 / Coverage¶
| 文件 / File | 检查重点 / Focus |
|---|---|
| 01 | 无初始空位,合并等均值家庭 / No initial empty position; equal-mean merging |
| 02 | 三种分数财富,位置恰好足够 / Three rational means, tight position count |
| 03 | 没有较富外部家庭 / No richer external household |
| 04 | 一种财富,极大合并人数 / One mean with a huge aggregated count |
| 05 | 两种有理数财富及未约分表示 / Two rational means in unreduced form |
| 06 | 三种接近的有理数财富 / Three nearby rational means |
| 07 | 最大财富及接近的整数均值 / Maximum money and nearby integer means |
| 08 | 组人数为模数减一、模数、模数加一 / Group sizes P−1, P, P+1 |
| 09 | 空家庭、零财富、三种随机均值 / Empties, zero money, three shuffled means |
| 10 | 单个目标,极大外部人数 / One target and huge outsider populations |
03至10均为百万家庭位置输入。 / Files 03–10 all contain one million household positions.
答案核验 / Answer verification¶
generate.py 自带全部核验算法:01–02使用精确 Fraction 网格;03–10由逐人平均直接构造下三角矩阵,再使用通用矩阵快速幂,不调用标准程序的尾和公式。此核验验证上界策略的计算,最优性依赖题解中的证明。
All oracles are included in generate.py: exact Fraction grids for 01–02, and generic matrix exponentiation built directly from individual averages for 03–10. The matrix oracle does not use the reference tail formula. It verifies the computation of the attaining strategy; optimality rests on the solution proof.
另有完整范围的 alternative-forward.cpp,编译方式与标准程序相同,需保留同目录的 wealth.hpp。两份程序完成400组精确网格及30组大人数矩阵对拍;再做2000组逐次合法搬家模拟,其中1552组初始没有空家庭。模拟始终保留固定位置与居民身份,最后达到上界。
The full-range alternative-forward.cpp compiles the same way as the reference; keep wealth.hpp in the same directory. Both programs pass 400 exact grids and 30 large-count matrix cases. Another 2000 legal-move simulations include 1552 initially full towns, checking fixed positions, identities, and attainment of the upper bound.
输入校验使用显式异常,正常模式和 python -O 均能拒绝越界、不满足位置保证、空户有财富及多余字段。输出校验要求恰好一个范围内整数,并比较期望值。每题6组样例与双语题面逐项核对。
Input validation uses explicit exceptions and rejects invalid bounds, insufficient positions, money in empty households, and extra fields in both normal and python -O modes. Output validation requires exactly one in-range integer matching the expected value. Each problem's six samples are matched against both language versions.
仓库级复现 / Repository-level reproduction¶
先将程序编译到 build/R42/,命名为 town-editing-simoleons-4-std.exe、town-editing-simoleons-5-std.exe、town-editing-simoleons-5-alternative-forward.exe,再从仓库根目录运行:
Compile programs into build/R42/ with the names above, then run from the repository root:
python tools/check_r42.py
python tools/check_r42_constructions.py
python tools/benchmark_r42.py
python tools/draw_r42_figures.py
python tools/check_statements.py
不要对包含 assert 的复现检查脚本启用 -O;输入校验器单独支持该模式。正式性能测量使用Windows工作集统计,每份输入计时五次、另测一次内存峰值,并记录输入、输出、程序和生成器哈希。其他平台须重新校准时限。
Do not use -O for reproduction scripts containing assertions; the input validator separately supports that mode. Performance measurements use Windows working-set statistics, five timings per file, and a separate peak-memory run. Input, output, program, and generator hashes are recorded. Recalibrate time limits on other platforms.
程序对拍 / Program comparisons · 合法搬家模拟 / Legal-move simulations · 正式测量 / Formal measurements · 逐次耗时及哈希 / Timings and hashes。