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 ...
随机推荐
- MySql The service could not be started
MySql安装 由于需要用mySql数据库今天就把它安上了,每次安装软件,数据库总是够我们折腾的,有时出现错误甚至比重装系统还要让人头疼. 今天在安的过程中就不出了很多错误,在重启与重装的反复捣鼓中终 ...
- c++拷贝构造函数(深拷贝,浅拷贝)详解
一.什么是拷贝构造函数 首先对于普通类型的对象来说,它们之间的复制是很简单的,例如: ; int b=a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量. 下面 ...
- mapreduce实战:统计美国各个气象站30年来的平均气温项目分析
气象数据集 我们要写一个气象数据挖掘的程序.气象数据是通过分布在美国各地区的很多气象传感器每隔一小时进行收集,这些数据是半结构化数据且是按照记录方式存储的,因此非常适合使用 MapReduce 程序来 ...
- java获取计算机硬件参数
public class HardWareUtils { /** * * 获取主板序列号 * * * * @return */ public static String g ...
- 自定义控件(视图)2期笔记10:自定义视图之View事件分发机制("瀑布流"的案例)
1. Touch事件的传递: 图解Touch事件的传递,如下: 当我们点击子View 02内部的Button控件时候,我们就触发了Touch事件. • 这个Touch事件首先传递给了顶级父View ...
- oracle:变长数组varray,嵌套表,集合
创建变长数组类型 ) ); 这个变长数组最多可以容纳两个数据,数据的类型为 varchar2(50) 更改元素类型的大小或精度 可以更改变长数组类型和嵌套表类型 元素的大小. ALTER TYPE ...
- Springmvc中@RequestParam传值中文乱码解决方案(转)
@RequestMapping(value={"/list"},method=RequestMethod.GET) @ResponseBody public DeviceList ...
- 自己写的自动生成动态边框的jquery小插件
思路就是在元素四周添加<ul>列表,然后周期性地改变它的颜色,实现动态的效果,不支持ie7.ie8 预览链接http://gorey.sinaapp.com/myBorder/border ...
- memcached和mongodb 在windows下安装
要在新机器上安装memcached和mongodb服务,折腾了一天,终于把这两个服务在windows下跑起来了. memcached主要参考http://www.rootop.org/pages/27 ...
- jquery选择器的使用方式
1.基本选择器 选择器 描述 返回 示例 代码说明 1 id选择器 根据指定的id匹配元素 单个元素 $("#one").css("background", ...