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 ...
随机推荐
- Android内存优化10 内存泄漏常见情况1 静态泄漏
1,内存泄漏到本质是该释放的对象被持久化的对象引用了,造成持久化的常见情况有1,静态持久化 2,线程持久化 线程持久化 因为存活的线程是有dvk虚拟久直接持有,所以存活的线程都是持久化的 内存泄漏1: ...
- 一键建立zookeeper集群
使用yaml文件的好处,通过service name来进行pod间的服务发现, 集群配置dns. [root@k8s-master ~]# cat zookeeper-cluster.yaml api ...
- 配置Node Manager启动同一机器的两个域
进入/u01/FMW_Home/weblogic/wlserver_10.3/server/bin目录,在需要配置的节点上启动node manager,以weblogic用户登录 c d /u01/F ...
- C++中try_catch_throw的做异常处理
C++中try_catch_throw的做异常处理 选择异常处理的编程方法的具体原因如下: . 把错误处理和真正的工作分开来: . 代码更易组织,更清晰,复杂的工作任务更容易实现: . 毫无疑问,更安 ...
- 统一D3D与OpenGL坐标系统
作者:游蓝海(http://blog.csdn.net/you_lan_hai) DirectX 3D与OpenGL坐标系统的差异性,给我们带来非常大的麻烦.让跨平台编程的新手非常困惑.近期在做一个跨 ...
- 轻松编写 C++ 单元测试
单元测试概述 测试并不只是测试工程师的责任,对于开发工程师,为了保证发布给测试环节的代码具有足够好的质量( Quality ),为所编写的功能代码编写适量的单元测试是十分必要的. 单元测试( Unit ...
- [PHP]如何使用Mobile_Detect来判断访问网站的设备:安卓,平板,电脑
Mobile_Detect 是一个轻量级的开源移动设备(手机)检测的 PHP Class, 它使用 User-Agent 中的字符串,并结合 HTTP Header,来检测移动设备环境. 这个设备检测 ...
- C# WinForm 异步执行耗时操作并将过程显示在界面中
private void button3_Click(object sender, EventArgs e) { RunAsync(() => ...
- spock spring 集成测试框架搭建心得
转载:http://blog.csdn.net/hankle_xu/article/details/77531880 spock测试框架,使用groovy作为脚本语言,开发出的测试脚本具有优良的阅读性 ...
- 常用命令(过滤、管道、重定向、ping 命令、netstat 命令、ps命令)
常用命令 过滤 过滤出 /etc/passwd 文件中包含 root 的记录 grep 'root' /etc/passwd 递归地过滤出 /var/log/ 目录中包含 linux 的记录 grep ...