csp初赛打程序模拟题和程序补全题有哪些技巧?
最近写了一些选择题 感觉还行
但是程序模拟就完了...
程序补全有的时候(运气好)还行,
运气不好:
CSP-J 2019 初赛 第20题到底啥意思啊
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 10000000;
const int maxs = 10000;
int n;
unsigned a[maxn], b[maxn],res[maxn], ord[maxn];
unsigned cnt[maxs + 1];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d%d", &a[i], &b[i]);
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < maxs; ++i)
++cnt[b[i]]; // 利用 cnt 数组统计数量
for (int i = 0; i < n; ++i)
cnt[i + 1] += cnt[i];
for (int i = 0; i < n; ++i)
ord[--cnt[b[i]]] = i; // 记录初步排序结果
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < n; ++i)
++cnt[a[i]]; // 利用 cnt 数组统计数量
for (int i = 0; i < maxs; ++i)
cnt[i + 1] += cnt[i];
for (int i = n - 1; i >= 0; --i)
res[--cnt[a[ord[i]]]] = ord[i]; // 记录最终排序结果
for (int i = 0; i < n; i++)
printf("%d %d", a[res[i]], b[res[i]]);
return 0;
}
我看答案补全了都没看懂.. /kk
(学过计数排序(没学过双关键字的), 也知道代码大概是干啥的, 但是细节还是不知道怎么补全...