codeforces Toy Sum
题意:给你x个集合的数,然后根据
求y集合的数。
思路:根据对称性,先找出对称出现的个数cnt,然后对称位置的中如果出现一个的把另一个加入到y集合中,再找出cnt个对应位置都不出现的加入到y集合中。
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#define ll long long
#define maxn 5000100
using namespace std; int n;
int x[maxn];
bool vis[maxn]; int main()
{
scanf("%d",&n);
ll s=;
set<int>q;
set<int>::iterator it;
int cnt=;
for(int i=; i<=n; i++)
{
scanf("%d",&x[i]);
vis[x[i]]=true;
}
for(int i=; i<=s/; i++)
{
int xx=s-(i-);
if(vis[i]&&vis[xx])
{
cnt++;
}
}
int j=;
ll cc=s-(j-);
while(j<=s/)
{
if((!vis[j])&&vis[cc])
{
q.insert(j);
}
else if(vis[j]&&(!vis[cc]))
{
q.insert(cc);
}
j++;
cc=s-(j-);
}
j=;
cc=s-(j-);
int t1=;
while(j<=s/&&t1<cnt)
{
if((!vis[j])&&(!vis[cc]))
{
q.insert(j);
q.insert(cc);
t1++;
}
if(t1==cnt) break;
j++;
cc=s-(j-);
}
printf("%d\n",(int)q.size());
for(it=q.begin(); it!=q.end(); it++)
{
printf("%d ",(*it));
}
printf("\n");
return ;
}
codeforces 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
D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
- 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 D. Toy Sum 解题报告
题目链接:http://codeforces.com/problemset/problem/405/D 题目意思:从 1 - 1000000 中选择 n 个数:x1,x2,...,xn,对 x1-1, ...
- D. Toy Sum(cf)
http://codeforces.com/problemset/problem/405/D 题意:已知集合S={1,2,3......1000000},s=1000000,从集合S中选择n个数,X= ...
- Codeforces 1442D - Sum(找性质+分治+背包)
Codeforces 题面传送门 & 洛谷题面传送门 智商掉线/ll 本来以为是个奇怪的反悔贪心,然后便一直往反悔贪心的方向想就没想出来,看了题解才发现是个 nb 结论题. Conclusio ...
- Codeforces 1303G - Sum of Prefix Sums(李超线段树+点分治)
Codeforces 题面传送门 & 洛谷题面传送门 个人感觉这题称不上毒瘤. 首先看到选一条路径之类的字眼可以轻松想到点分治,也就是我们每次取原树的重心 \(r\) 并将路径分为经过重心和不 ...
- codeforces 616E Sum of Remainders (数论,找规律)
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- 使用jq工具在Shell命令行处理JSON数据
由于近期要处理一些 JSON 数据格式.一大早经过一番搜索后,终于找到了 jq 这个非常棒的工具.jq 同意你直接在命令行下对 JSON 进行操作,包含分片.过滤.转换等等. 首先在mac下安装jq. ...
- [转] 学习使用:before和:after伪元素
http://www.w3cplus.com/css3/learning-to-use-the-before-and-after-pseudo-elements-in-css.html 如果你一直密切 ...
- 《Android群英传》读书笔记 (5) 第十一章 搭建云端服务器 + 第十二章 Android 5.X新特性详解 + 第十三章 Android实例提高
第十一章 搭建云端服务器 该章主要介绍了移动后端服务的概念以及Bmob的使用,比较简单,所以略过不总结. 第十三章 Android实例提高 该章主要介绍了拼图游戏和2048的小项目实例,主要是代码,所 ...
- Eclipse中文语言包下载
Kepler .Juno . Indigo语言包: http://www.eclipse.org/babel/downloads.php 其他低版本Eclipse语言包下载: http://archi ...
- MySQL日志概述
为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/3859866.html ...
- CakePHP的blog教程三
简单的身份验证和授权应用 接着我们blog教程的例子,如果我们想要建立一个根据登录的用户身份来决定其安全访问到正确的urls. 同时我们还有其他的需求: 允许我们的blog有多个作者,每一个作者都可以 ...
- ImageView 设置OnTouchListener
ImageView的OnTouchListener,onTouch方法要返回true,MotionEvent.ACTION_UP,MotionEvent.ACTION_MOVE 才有效. 其实关于返回 ...
- EntityFrameowk6.1 使用enum和低版本的不同
原有项目中使用EF5.0 实体类 public partial class Log : BaseEntity { public Nullable<int> LogLevelId { get ...
- Relative与Absolute组合使用
小伙伴们学习了绝对定位的方法:使用position:absolute可以实现被设置元素相对于浏览器(body)设置定位以后, 大家有没有想过可不可以相对于其它元素进行定位呢?答案是肯定的,当然可以.使 ...
- 【HDU3802】【降幂大法+矩阵加速+特征方程】Ipad,IPhone
Problem Description In ACM_DIY, there is one master called “Lost”. As we know he is a “-2Dai”, which ...