CSPJ2019 完善程序
程序二
#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 < n; ++i) ① ; //利用cnt数组统计数量 for (int i = 0; i < maxs; ++i) cnt[i + 1] += cnt[i]; for (int i = 0; i < n; ++i) ② ; //记录初步排序结果 memset(cnt, 0 , sizeof(cnt)); for (int i = 0; i < n; ++i) ③ ; //利用cnt数组统计数量 for (int i = 0; i < maxs; ++i) cnt[i + 1] += cnt[i]; for (int i = n - 1; i >= 0; --i) ④ ; //记录最终排序结果 for (int i = 0; i < n; ++i) printf("%d %d\n", ⑤); return 0; }
①处应填( )
++cnt[i]
++cnt[b[i]]
++cnt[a[i] * maxs + b[i]]
++cnt[a[i]]
②处应填( )
ord[--cnt[a[i]]] = i
ord[--cnt[b[i]]] = a[i]
ord[--cnt[a[i]]] = b[i]
ord[--cnt[b[i]]] = i
③处应填()
++cnt[b[i]]
++cnt[a[i] * maxs + b[i]]
++cnt[a[i]]
++cnt[i]
④处应填()
res[--cnt[a[ord[i]]]] = ord[i]
res[--cnt[b[ord[i]]]] = ord[i]
res[--cnt[b[i]]] = ord[i]
res[--cnt[a[i]]] = ord[i]
⑤处应填()
a[i], b[i]
a[res[i]], b[res[i]]
a[ord[res[i]]] , b[ord[res[i]]]
a[res[ord[i]]] , b[res[ord[i]]]
发表评论