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 ScrollView 充满屏幕
android:fillViewport=true ScrollView下面的组件如果有android:layout_height="fill_parent"或android:la ...
- ||和 && 符号的赋值运用(转)
javascript “||”.“&&”的灵活运用 博客分类: Jquery javascript javascript中运用“||”.“&&”javascript 真 ...
- android 57 QQ登录
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&q ...
- Java语言基础(五)
Java语言基础(五) 一.浮点数 浮点数就是小数,其标准是IEEE 754,用指数和尾数表示 例如30000=3*10000=3*10^4 其中4是指数,3是尾数 Java中,浮点数有float ...
- java输入输出
1. import java.io.*;//写进文档,然后又在显示器显示出来.public class fileinputstream{public static void main(String[] ...
- SDL Game Development InputHandler类的一处bug
个人十分推荐SDL Game Development 这本书,它并不是死抠SDL的api,而是一步步带着我们如何对一个游戏进行构架. 虽然我没用过游戏引擎,也基本不会写游戏,但是我认为这本书本身就是在 ...
- Maven学习总结——聚合与继承
一.聚合 如果我们想一次构建多个项目模块,那我们就需要对多个项目模块进行聚合 1.1.聚合配置代码 1 <modules> 2 <module>模块一</module&g ...
- Android Activity各启动模式的差异
Activity共有四种启动模式:standard,singleTop,singleTask,singleInstance 为了方便描述和理解,布局文件.Manifest文件和各个java文件如下: ...
- NSDate和NSString的转换及判定是昨天,今天,明天
用于uidate,picker.. +(NSDate*) convertDateFromString:(NSString*)uiDate{ NSDateFormatter *formatter ...
- JavaScript Window Screen
window.screen 对象包含有关用户屏幕的信息. Window Screen window.screen对象在编写时可以不使用 window 这个前缀. 一些属性: screen.availW ...