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. ToolBar存档

    上图是将本阶段要完成的结果画面做了标示,结合下面的描述希望大家能明白. colorPrimaryDark(状态栏底色):在风格 (styles) 或是主题 (themes) 里进行设定. App ba ...

  2. core java 8~9(GUI & AWT事件处理机制)

    MODULE 8 GUIs--------------------------------GUI中的包: java.awt.*; javax.swing.*; java.awt.event.*; 要求 ...

  3. Go defer延迟执行

    defer用于延迟执行,可以类比于java或c++中的析构函数. 查看一段示例代码: func Contents(filename string) (string, error) { //打开文件 f ...

  4. bootsrap check 获取选中

    代码如下: <label> <input type="checkbox" name="PartEdge2" value="false ...

  5. 可综合风格的VerilogHDL模块实例

    1.赋值语句:assign{cout,sum}=a+b+cin; 2.利用电平敏感的always块设计组合逻辑电路 3.always块中如果含有局部变量,就必须在begin后加模块名,是必须加,同样的 ...

  6. 28335 sci fifo send

    #include "DSP2833x_Device.h"#include "DSP2833x_Examples.h"char buf[]={0x30,0x32, ...

  7. Linux 删除mysql数据库失败的解决方法

    使用命令:drop database xxx:删除本数据库时却删除失败,系统提示出现了错误,错误代码为: ERROR 1010 (HY000): Error dropping database(can ...

  8. java判断某个字符串包含某个字符串的个数

    /** * 判断str1中包含str2的个数 * @param str1 * @param str2 * @return counter */ public static int countStr(S ...

  9. 利用FormsAuthentication.RedirectFromLoginPage进行身份验证

    web.config中: <authentication>节 格式: <authentication mode="Forms">    //I.Window ...

  10. C语言中结构体的初始化

    直接上例子: struct point { int x; int y; int z; } //常规写法 struct point pt1 = {100, 300, 200}; //初始化个数少于实际个 ...