D. Toy Sum
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.

There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:

"Are you kidding me?", asks Chris.

For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.

However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e.xi ≠ yj for all ij (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

Sample test(s)
input
3
1 4 5
output
2
999993 1000000
input
1
1
output
1
1000000 如果X 集合中存在元素 i 若 s(10 ^ 6) - i + 1不在集合中则可以直接输出 s - i + 1,否则出现两个数同时出现在集合中,则可以用另外的i s - i + 1去代替
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn 1000005 int a[maxn];
int n,s = maxn - ; int main() {
//freopen("sw.in","r",stdin);
scanf("%d",&n); for(int i = ; i <= n; ++i) {
int ch;
scanf("%d",&ch);
++a[ch];
} printf("%d\n",n);
for(int i = ; i <= maxn - ; ++i) {
if(a[i] > && a[s - i + ] == ) {
printf("%d ",s - i + );
--n;
}
}
for(int i = ; i <= s && n; ++i) {
if(a[i] == && a[s - i + ] == ) {
printf("%d %d ",i,s - i + );
n -= ;
}
} return ; }

cf div2 238 D的更多相关文章

  1. cf div2 238 c

    C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. cf div2 234 D

    D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  3. 离线dfs CF div2 707 D

    http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...

  4. cf div2 239 D

    D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  5. cf div2 236 D

    D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. cf div2 237 D

    D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  7. cf div2 235 D

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  8. cf div2 234 E

    E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...

  9. CF div2 D BFS

    http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...

随机推荐

  1. C#调用C++ Dll

    现在项目基本都是旁边C++的哥们做好dll扔给我,然后我调用.好久之前晚上down了一份c#调用c++dll的方法,出处早已经遗忘.闲来无事,放上来好了.原作者看到后可以留言,我会把您链接放上的,帮了 ...

  2. SQL基础知识----数据类型

    VARCHAR(VERiable CHARacter):可变动字符.用于保存以文本格式处处的信息,最大可以储存255个字符.一般使用为VAECHAR(10)   --表示最多可以存储10个字符 INT ...

  3. DIV指令一般用法

    本文最初发表于2015-8-14,是由别的地方迁移过来的 (本文所讲为无符号运算) DIV指令是8086汇编中的除法运算指令,它的结果不是浮点数,而是两个整数:商和余数. 我们来看王爽老师是怎么讲的: ...

  4. 内核同步机制 RCU

    Evernote分享地址:http://www.evernote.com/shard/s133/sh/8807320d-f54d-4e90-a31b-e2a3d35509ee/7539dc3931b8 ...

  5. arcgis中求多点到一条曲线的最短欧几里得距离

    1.使用的工具:Arctoolbox----Analysis Tools----Proximity----Near工具. 2.注意:在求距离之前一定要先设置好坐标系统.

  6. jquery 简单弹出层

    预定义html代码:没有 所有代码通过js生成和移除. 预定义css .z-popup-overlay{ width:100%; min-height: 100%; height:800px; pos ...

  7. Linux开机启动程序详解

    Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...

  8. shell 函数

    1 shell函数的定义及其调用 shell函数有两种格式: function name { commands } name() { commands } 其中,name为函数名,commands为函 ...

  9. VS中引用第三方库的方法(配置sqlite数据库)

    我们在编写程序时,,不可避免的会使用第三方的库文件,很少使用源文件(.cpp),大部分是使用对类进行声明的头文件和封装了类的链接库(静态lib或动态dll),比如我们写程序用的iostream这个库, ...

  10. 使用xilinx ip core FIFO First- World First-Through (FWFT)模式的注意事项

    也许很多人知道xilinx ip core 中的fifo可以配成standard 模式和FWFT模式,并知道两者的区别是:standard模式下,当rd为高时,fifo会延时一个时钟输出数据(时序逻辑 ...