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 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.

Sample test(s)
Input
3
1 4 5
Output
2
999993 1000000
Input
1
1
Output
1
1000000
讲解:题目大意是说,范围为大于等于 1 ,小于等于 1000000 ;首先从中选出 n 个数,每个数减去 1 ,假设和为 ans ;
然后需要你从中取出 m 个数,且不能与给的数重复,用1000000减去你选出的每个数,然后求和,和也为 ans ;
然后就寻找吧,唉,这题咋这么绕呢,看着简单,好难写啊;
 #include <set>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = ;
int a[N];
bool mark[N];
int main(){
int n;
cin>>n;
int s= ;
set<int>y;
vector<int>notexist;
for(int i=;i<n;i++){
scanf("%d",&a[i]);
mark[a[i]] = true;
}
for(int i=;i<=s;i++){
if(mark[i]&&!mark[s+-i]) //已经标记过了,并且差没出现过,则存入容器;
{
y.insert(s+-i);
}
if(!mark[i]&&!mark[s+-i]) //都没出现过;
notexist.push_back(i);
}
int j = ;
for(int i=; i<=s/; i++){
if(mark[i] && mark[s+-i])//说明,需要重新插入连个没有被标记的数,固定的和为 s+1 ;
{
y.insert(notexist[j]);
y.insert(s+-notexist[j]);
j++;
}
}
cout<<n<<endl;
set<int>::iterator it = y.begin();
while(it!=y.end())
{
printf("%d ",*it);
it++;
}
return ;
}

Codeforces Round #238 (Div. 2) D. Toy Sum的更多相关文章

  1. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  2. Codeforces Round #238 (Div. 2) D. Toy Sum(想法题)

     传送门 Description Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to s ...

  3. 水题 Codeforces Round #303 (Div. 2) A. Toy Cars

    题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...

  4. Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

    Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...

  5. Codeforces Round #238 (Div. 1)

    感觉这场题目有种似曾相识感觉,C题还没看,日后补上.一定要坚持做下去. A Unusual Product 题意: 给定一个n*n的01矩阵,3种操作, 1 i 将第i行翻转 2 i 将第i列翻转 3 ...

  6. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  7. Codeforces Round #303 (Div. 2) A. Toy Cars 水题

     A. Toy Cars Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem ...

  8. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  9. Codeforces Round #232 (Div. 2) D. On Sum of Fractions

    D. On Sum of Fractions Let's assume that v(n) is the largest prime number, that does not exceed n; u ...

随机推荐

  1. 降维工具箱drtool

    工具箱下载:http://leelab.googlecode.com/svn/trunk/apps/drtoolbox/ ——————————————————————————————————————— ...

  2. easyui时间控件设置为可清空——jquery-easyui-1.3.3(这个版本还没有buttons,网上的好多博文都是1.3.5之后的版本)

    效果图: 更改的源码jquery.easyui.min.js 11358行: var _858=$("<div class=\"datebox-button\"&g ...

  3. [转]sql server transaction

    本文转自: http://www.2cto.com/database/201208/146734.html sql事务(Transaction)用法介绍及回滚实例   事务(Transaction)是 ...

  4. threadlocal 变量 跟synchronized 关键字的关系

    为什么叫threadloca变量呢,经过大量的查资料发现threadlocal并不是之前理解的控制线程用的东西,它其实也属于一类变量,只不过是线程的局部变量,它的作用就是实现线程间对该变量的唯一线程调 ...

  5. Struts2中的页面跳转

    内容源自:Struts2中的页面跳转 一.全局页面的设置如果<package>包中的一些action都返回success,并且返回的页面都是同一个JSP页面,这样就可以配置全局的结果页面. ...

  6. 不要在基类析构函数中调用纯虚函数,否则运行时会报错“pure virtual method called”

    如上. 这是因为:delete派生类对象时,先调用派生类的析构函数,然后再调用基类的析构函数:此时如果调用纯虚函数的话,派生类的对象已经被破坏了,所以会报错. http://www.cnblogs.c ...

  7. html中锚点的应用【本页面跳转】

    设置锚点 <a name="top"></a> 同页跳转 <a href="#top">返回顶部</a> 不同页 ...

  8. freemarker的list指令小技术归纳

    1.问题:当数据超过3位的时候,freemarker会自动用逗号截取,例如2,311 解决方法(一种即可): (1)加.toString(),如:${(data).toString()} (2)加?c ...

  9. vue - 实例事件

    1.$on(在构造器外部添加事件) 2.$once(执行一次的事件) 3.$off(关闭事件) 4.$emit(事件调用) <!DOCTYPE html> <html lang=&q ...

  10. vue - (v-pre、v-cloak、v-once)

    1.v-pre,不和绑定的数据冲突,也就是不用它们的值 2.v-cloak,和css样式一起用,vue渲染未完成不显示 3.v-once,只渲染DOM第一次渲染的值,以后不会改变了(你不要刷新网页,然 ...