zoukankan      html  css  js  c++  java
  • cf div2 238 D

    D. Toy Sum
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 subset Y 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 test(s)
    input
    3
    1 4 5
    output
    2
    999993 1000000
    input
    1
    1
    output
    1
    1000000


    如果X 集合中存在元素 i 若 s(10 ^ 6) - i + 1不在集合中则可以直接输出 s - i + 1,否则出现两个数同时出现在集合中,则可以用另外的i s - i + 1去代替

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <iostream>
     5 
     6 using namespace std;
     7 
     8 #define maxn 1000005
     9 
    10 int a[maxn];
    11 int n,s = maxn - 5;
    12 
    13 int main() {
    14         //freopen("sw.in","r",stdin);
    15         scanf("%d",&n);
    16 
    17         for(int i = 1; i <= n; ++i) {
    18                 int ch;
    19                 scanf("%d",&ch);
    20                 ++a[ch];
    21         }
    22 
    23         printf("%d
    ",n);
    24         for(int i = 1; i <= maxn - 5; ++i) {
    25                 if(a[i] > 0 && a[s - i + 1] == 0) {
    26                         printf("%d ",s - i + 1);
    27                         --n;
    28                 }
    29         }
    30         for(int i = 1; i <= s && n; ++i) {
    31                 if(a[i] == 0 && a[s - i + 1] == 0) {
    32                         printf("%d %d ",i,s - i + 1);
    33                         n -= 2;
    34                 }
    35         }
    36 
    37         return 0;
    38 
    39 }
    View Code
  • 相关阅读:
    jmeter如何操作数据库
    jmeter压力测试
    cmd中用ping命令时,提示ping命令不是外部或内部命令问题
    scrapy post Request payload类型值
    scrapy-deltafetch实现增量爬取
    django虚拟环境搭建笔记
    python Image模块基本语法
    登录北京住房公积金,使用已注册过账号
    登录北京社保网站
    python通过pop3方式登录邮箱(qq,新浪,网易)
  • 原文地址:https://www.cnblogs.com/hyxsolitude/p/3620015.html
Copyright © 2011-2022 走看看