codeforces Toy Sum

时间:2023-03-09 23:18:48
codeforces Toy Sum

题意:给你x个集合的数,然后根据codeforces Toy Sum求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 ;
}