const int MAXN = 1000010; int vis[MAXN]; const int MID = 1000001; int main() { // freopen("in.txt", "r", stdin); int n, t; while (~RI(n)) { CLR(vis, 0); REP(i, n) { RI(t); vis[t]++; } vector<int> ans; int need = 0; FE(i, 1, 1000000) { if (vis[i]) { if (!vis[MID - i]) ans.push_back(MID - i); else need++; } } need /= 2; int len = ans.size(); REP(i, len) vis[ans[i]]++; for (int i = 1; need && i <= 1000000; i++) { if (!vis[i] && !vis[MID - i]) { need--; ans.push_back(i); ans.push_back(MID - i); } } if (need) ans.push_back(1000000); len = ans.size(); WI(len); REP(i, len) { if (i != 0) putchar(‘ ‘); printf("%d", ans[i]); } puts(""); } return 0; }
Codeforces Round #238 (Div. 1)__Toy Sum,布布扣,bubuko.com
Codeforces Round #238 (Div. 1)__Toy Sum
原文:http://blog.csdn.net/wty__/article/details/21873913