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 ...
随机推荐
- Android中Style和Theme的使用
Style: Style是View中一些属性的集合,包括height,padding,font color,background等等,Style单独定义在xml文件中,类似与web页面中css的角色, ...
- 轻量级的原型设计工具-Axure RP
1. 软件下载地址: http://www.downxia.com/downinfo/25742.html 这个版本不需要注册码,不需要安装,存绿色版. 2. 基本介绍教程: http://wenku ...
- spring beans源码解读之--BeanFactory的注册
beanFactory的继承关系如下图所示: (图片来源:http://www.myexception.cn/software-architecture-design/925888.html) 在上节 ...
- windows10UWP:如何判断一个文件或者文件夹是否存在?
使用 StorageFolder.TryGetItemAsync 方法,尝试按名称获取文件或文件夹,不需将错误捕捉逻辑添加到代码(就像使用 StorageFolder.GetItemAsync 一样) ...
- NUll在oracle与sqlserver中使用相同与区别
最近在使用Oracle进行开发,遇到很多与以前使用sqlserver的不同语法.今天遇到null在两种数据库上面操作上的差别,在此记录两种数据库上的差异. null 与字符串相加 1.在oracle中 ...
- jquery生产和开发的区别
今天说一下jquery生产和开发的区别,在我们下载jquery的时候,会有两个下载链接,一个是jquery.min.js .迷你版 (生产),另一个是 jquery.js .开发版 .不知道的人可能就 ...
- MVC中javascript直接调用Model
最近做一个统计页面, Model从后台已经获取了数据集合,想直接在前台展示,而这个展示是需要用js生成图表的. 控制器部分代码: public ActionResult Index() { var m ...
- switch语法之PHP
$a = 100; switch ($a) { case 100: echo '满分'; break; case $a >=60: echo '及格'; break; }
- iOS6以后的单个控制器横竖屏显示以及旋转屏控制技巧,附带iOS8以后显示电池状态栏
一.在应用中从竖屏模式强制转换为横屏模式 第一种方法:通过模态弹出视图的方式,使得特定ViewController坚持特定的interfaceOrientation(1)iOS6之后提供了这样一个方法 ...
- 导入Android工程源码出现乱码问题的解决方法
可以尝试着从以下三个方法进行调试,一般情况下会完美解决的: 1.windows->Preferences->General->Content Types->Text->J ...