codeforces405D
Toy Sum
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 Yshould 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.
Examples
3
1 4 5
2
999993 1000000
1
1
1
1000000 sol:显然可以从两边往中间做,如果一边有就弄另一边,两边都有就弄一对新的即可
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int S=,n,m=,a[N],b[N];
bool Bo[N];
int main()
{
int i;
R(n);
for(i=;i<=n;i++) Bo[a[i]=read()]=;
int up=S>>,cnt=;
for(i=;i<=up;i++)
{
int o1=i,o2=S-i+;
if((Bo[o1])&&(!Bo[o2]))
{
b[++m]=o2; Bo[o2]=;
}
else if((!Bo[o1])&&(Bo[o2]))
{
b[++m]=o1; Bo[o1]=;
}
else if(Bo[o1]&&Bo[o2]) cnt++;
}
for(i=;i<=up&&cnt;i++)
{
if(!Bo[i])
{
b[++m]=i; b[++m]=S-i+; cnt--;
}
}
sort(b+,b+m+);
Wl(m);
for(i=;i<=m;i++) W(b[i]);
return ;
}
codeforces405D的更多相关文章
随机推荐
- Spark机器学习API之特征处理(一)
Spark机器学习库中包含了两种实现方式,一种是spark.mllib,这种是基础的API,基于RDDs之上构建,另一种是spark.ml,这种是higher-level API,基于DataFram ...
- C#/.net中出现 "GDI+中发生一般性错误"解决方案
有时我们在读取本地图片,调用 Image.Save() 方法,将其另保存为其他格式时,经常会碰到一个错误:“GDI+中发生一般性错误”:一般出现这种错误有 3 种可能: 1.保存路径不存在或者错误: ...
- What is libacl.so.1 ?
Google says, "This package contains the libacl.so dynamic library which contains the POSIX 1003 ...
- 实时跟踪之TRACA
背景: 目前,在实时跟踪领域存在着越来越多的先进方法,同时也极大地促进了该领域的发展.主要有两种不同的基于深度学习的跟踪方法:1.由在线跟踪器组成,这些跟踪器依赖网络连续的微调来学习目标的变化外观,精 ...
- 三:MVC之Lambda表达式
Lambda表达式 Lambda表达式是一个匿名方法,即没有方法名的方法. C#中的Lambda表达式使用Lambda运算符“=>”,该运算符读为“goes to”. 语法: 形参列表=> ...
- 06_Hive分桶机制及其作用
1.Clustered By 对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分. Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后 ...
- Linux磁盘及文件系统管理2
创建文件系统: 格式化:低级格式化(分区之前进行,划分磁道).高级格式化(分区之后对分区进行,创建文件系统) 元数据区,数据区 元数据区: 文件元数据:inode(index node) 大小.权限. ...
- 数据结构课后练习题(练习三)7-5 Tree Traversals Again (25 分)
7-5 Tree Traversals Again (25 分) An inorder binary tree traversal can be implemented in a non-recu ...
- 3. caffe中 python Notebook
caffe官网上的example中的例子,如果环境配对都能跑出来,接下来跑Notobook Example中的程序,都是python写的,这些程序会让你对如何使用caffe解决问题有个初步的了解(ht ...
- bzoj 1787 && bzoj 1832: [Ahoi2008]Meet 紧急集合(倍增LCA)算法竞赛进阶指南
题目描述 原题连接 Y岛风景美丽宜人,气候温和,物产丰富. Y岛上有N个城市(编号\(1,2,-,N\)),有\(N-1\)条城市间的道路连接着它们. 每一条道路都连接某两个城市. 幸运的是,小可可通 ...