CodeForces 405D Toy Sum【思维】

来源:互联网 发布:公司网络屏蔽qq 编辑:程序博客网 时间:2024/05/16 12:12

Description

Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.

There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subsetY from the remaining blocks, that the equality holds:

"Are you kidding me?", asks Chris.

For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.

However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

Input

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1x2...xn (1 ≤ xi ≤ 106), the numbers of the blocks in X.

Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

Output

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1y2...ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all ij (1 ≤ i ≤ n1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

Sample Input

Input
31 4 5
Output
2999993 1000000
Input
11
Output
11000000 

/*    题意:给你1~s (1e6) 的全集,选出n个数字组成子集,子集的和定义为 每个元素-1 的和,          要你从全集中剩余的元素里面挑若干个,使得新子集的和等于子集的和,但是          新子集的和定义为 1e6-每个元素 的和    类型:思维    分析:假设挑出的数字为x,那么我们需要寻找y满足条件的数字是 x-1=s-y,即y=s-x+1          当y不在子集中时,直接拿走;          当y在子集中时,那必然是因为x和后面的某个x'构成对称性,即x+x' = s+1;          那么我们同时处理这两个元素,可以得到一个恒定的值x-1 + x'-1 = s-1;          对于这个恒定的值 我们可以直接找对称的两个不在子集中的元素,因为          y+y' = s+1          s-y+s-y' = s+s-(s+1)=s-1;          故此 这道题得以解决*/#include<cstdio>#include<cstring>#include<iostream>#include<vector>using namespace std;const int maxs = 1000005;const int maxn = 500005;const int s = 1000000;int a[maxn];int b[maxs];vector<int>v;int main(){   // freopen("F:\\input.txt","r",stdin);    int n;cin>>n;   // int sum1=0;    for(int i=0;i<n;i++){        scanf("%d",&a[i]);        b[a[i]]=1;       //sum1+=a[i]-1;    }    int cnt=0;    for(int i=0;i<n;i++){        if(b[s-a[i]+1]==0){            v.push_back(s-a[i]+1);            b[s-a[i]+1]=1;        }        else cnt++;    }    for(int i=1;i<=s&&cnt;i++){        if(!b[i]&&!b[s-i+1]){            v.push_back(i);            b[i]=1;            v.push_back(s+1-i);            b[s+1-i]=1;            cnt-=2;        }    }    int len=v.size();    cout<<len<<endl;   //int sum=0;    for(int i=0;i<len;i++){        printf("%d%c",v[i],i==len-1?'\n':' ');        //sum+=s-v[i];    }    //cout<<sum<<endl;    //cout<<sum1<<endl;    return 0;}




0 0
原创粉丝点击