cf div2 238 D
1 second
256 megabytes
standard input
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!
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++.
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 i, j (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.
3
1 4 5
2
999993 1000000
1
1
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的更多相关文章
- cf div2 238 c
C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 237 D
D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- CF div2 D BFS
http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- Paragon NTFS for Mac免费获取官方赠送正版.更新获取ntfs for mac 14方法
Paragon NTFS for Mac免费获取官方赠送正版,没有这个软件的朋友赶紧收下.获取地址http://www.paragon-drivers.com/cn/ntfs-mac-free/ntf ...
- 时隔3年半Spring.NET 2.0终于正式Release了
一直很喜欢Spring.NET,不过2011年8月2日1.3.2正式release之后,再没有正式版本的release了. 直到4天前,Spring.NET 2.0 GA终于Release. http ...
- ubuntu下xampp的安装
转载:http://blog.csdn.net/zhoushengchao/article/details/6006584 首先,请从www.xampp.org下载最新版XAMPP.然后,将安装文件服 ...
- Java Day 16
基本数据类型包装类 Integer.MAX_VALUE Integer.parseInt(); intValue(); valueOf(); 自动装拆箱 如果是一个字节范围,数据共享 字符串中 数值 ...
- C++中栈的出栈,入栈规则:A,B,C,D,E
考题: 栈底至栈顶一次存放元素 ABCD 在第五个元素E入栈之前 栈中元素可以出栈,则出栈序列可能是_____a d___________. a. ABCED b. DBCEA c. CD ...
- 简单修改 MySQL 的 root 账号密码
首先这是一篇非常非常初级的教程. 平时为了方便,经常是直接在网上下载 PHP + MySQL 的集成环境,但有一些 MySQL 的 root 账号是没有密码的(例如大名鼎鼎的 XAMPP 就是这样), ...
- 创建ubuntu软件源
缘起:虚拟机需要安装一些文件,但是直接从外网下载比较慢,而且安装iso包中是有这些软件的,所以创建一个ubuntu apt server ubuntu 12.04, 本机192.168.0.124, ...
- android 开发怎么让程序生成的图片文件不会被系统扫描到
我们在写应用的时候,可能会保存很多图片,大的小的,仅仅是我们的应用中会用到,处于种种原因不希望用户看到,我是觉着如果被用户看到了,就失去了我的应用的那一层神秘的面纱,用户是米有闲情逸致去打开你一层层的 ...
- 代码复用 -- 深入了解javascript
/* 代码复用 */ /* 一.避免 */ /* 模式1:默认模式 */ function Parent() { this.name = "123"; } Parent.proto ...
- OS X 使用技巧——访问所有的键盘功能
苹果笔记本电脑和苹果的无线键盘只有一个Delete键,可以删除光标前面的字. 按住Fn键再按Delete键就能删除光标后面的字符. 按住Fn键会把上下方向键的效果变成Page Up / Page Do ...