Codeforces Round #238 (Div. 2) D. 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!
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
讲解:题目大意是说,范围为大于等于 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的更多相关文章
- 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 ...
- 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 ...
- 水题 Codeforces Round #303 (Div. 2) A. Toy Cars
题目传送门 /* 题意:5种情况对应对应第i或j辆车翻了没 水题:其实就看对角线的上半边就可以了,vis判断,可惜WA了一次 3: if both cars turned over during th ...
- Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)
Problem Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Descripti ...
- Codeforces Round #238 (Div. 1)
感觉这场题目有种似曾相识感觉,C题还没看,日后补上.一定要坚持做下去. A Unusual Product 题意: 给定一个n*n的01矩阵,3种操作, 1 i 将第i行翻转 2 i 将第i列翻转 3 ...
- 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/ ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 修复CentOS文件系统
CentOS经常出现一些像 Cannot mkdir: Structure needs cleaning 的文件系统错误,而且在正常模式下无法umount来进行修复.很多时候只能在rescue模式下进 ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-如何使用随机数DRAND模块
DRAND函数可以产生0-1的随机浮点数 DRAND的输入Seed有什么意义? 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/aceta ...
- Django 学习记录
这是我自己理解并自己画的,django 请求示意图,表示了它的组织方式. project manage.py: 主要工具文件 settings.py: 配置文件 urls.py: url 定义及其指向 ...
- 【大盛】全网首发HTC One/M7 最新本地化TrickDroid9.0/固件升级/永久root/高级,快速设置/稳定,流畅经典ROM
了解更多请关注:点击打开链接 ROM版本 HTC One/M7_TrickDroid9.0.0 ROM作者 雪狼团队-大盛 http://weibo.com/DaShengdd Android版本 ...
- [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第九章 内存管理
内存管理: 确保在须要的时候分配内存,在程序运行结束时释放占用的内存 假设仅仅分配内存而不释放内存,则会发生内存泄漏(leak memory),程序的内存占用量不断添加.终于会被耗尽并导致程序崩溃. ...
- 2019pycharm破解大法
通过激活码激活Pycharm 1 先找到你的hosts文件: Windows电脑:c:\windows\system32\drivers\etc Linux/Mac电脑:/etc 2 编辑hosts文 ...
- 我的Go语言学习之旅二:入门初体验 Hello World
好吧,全部的程序猿们都已经习惯了.学习不论什么一门语言,我们都会以Hello World实例開始我们的学习,我也不例外.先来一个简单的样例 打开编辑器 (能够用记事本,我已经习惯 Notepad++了 ...
- Spring Boot(一)启动方式
1.系统自动生成 SpringApplication.run(XX.class, args); 2.创建SpringApplication对象 SpringApplication app = new ...
- Mybatis <where>标签
<select id="findActiveBlogLike" resultType="Blog"> SELECT * FROM BLOG WHER ...
- Android 6.0 超级简单的权限申请2 (Permission)
代码地址如下:http://www.demodashi.com/demo/13506.html 写在前面 上次写了一个权限申请的例子Android 6.0 超级简单的权限申请 (Permission) ...