• Long Jumps CodeForces


    Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!

    However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measurements. We assume that the marks are numbered from 1 to n in the order they appear from the beginning of the ruler to its end. The first point coincides with the beginning of the ruler and represents the origin. The last mark coincides with the end of the ruler, at distance l from the origin. This ruler can be repesented by an increasing sequence a1, a2, ..., an, where ai denotes the distance of the i-th mark from the origin (a1 = 0, an = l).

    Valery believes that with a ruler he can measure the distance of d centimeters, if there is a pair of integers i and j (1 ≤ i ≤ j ≤ n), such that the distance between thei-th and the j-th mark is exactly equal to d (in other words, aj - ai = d).

    Under the rules, the girls should be able to jump at least x centimeters, and the boys should be able to jump at least y (x < y) centimeters. To test the children's abilities, Valery needs a ruler to measure each of the distances x and y.

    Your task is to determine what is the minimum number of additional marks you need to add on the ruler so that they can be used to measure the distances x and y. Valery can add the marks at any integer non-negative distance from the origin not exceeding the length of the ruler.

    Input

    The first line contains four positive space-separated integers nlxy (2 ≤ n ≤ 105,2 ≤ l ≤ 1091 ≤ x < y ≤ l) — the number of marks, the length of the ruler and the jump norms for girls and boys, correspondingly.

    The second line contains a sequence of n integers a1, a2, ..., an (0 = a1 < a2 < ... < an = l), where ai shows the distance from the i-th mark to the origin.

    Output

    In the first line print a single non-negative integer v — the minimum number of marks that you need to add on the ruler.

    In the second line print v space-separated integers p1, p2, ..., pv (0 ≤ pi ≤ l). Numberpi means that the i-th mark should be at the distance of pi centimeters from the origin. Print the marks in any order. If there are multiple solutions, print any of them.

    Example

    Input
    3 250 185 230
    0 185 250
    Output
    1
    230
    Input
    4 250 185 230
    0 20 185 250
    Output
    0
    Input
    2 300 185 230
    0 300
    Output
      1 #include <iostream>
      2 using namespace std;
      3 #include<stack>
      4 #include<stdio.h>
      5 #include<math.h>
      6 #include<string.h>
      7 #include<map>
      8 #include<queue>
      9 #include<algorithm>
     10 #include<map>
     11 #include<cstdio>
     12 #include<cstring>
     13 int a[111111];
     14 int n;
     15 bool bin_search(int x)
     16 {
     17     int l,r,mid;
     18     l=1;
     19     r=n;
     20     while(l<=r)
     21     {
     22         mid=(l+r)>>1;
     23         if(a[mid]<x)
     24             l=mid+1;
     25         else if(a[mid]>x)
     26             r=mid-1;
     27         else
     28             return 1;
     29     }
     30     return 0;
     31 }
     32 int main()
     33 {
     34     int l,x,y;
     35     int i;
     36     bool flag1,flag2;
     37     scanf("%d%d%d%d",&n,&l,&x,&y);
     38         for(i=1;i<=n;i++)
     39             scanf("%d",&a[i]);
     40         flag1=flag2=0;
     41         for(i=1;i<=n;i++)
     42         {
     43             if(bin_search(a[i]+x))
     44             {
     45                 flag1=1;
     46                 break;
     47             }
     48         }
     49         for(i=1;i<=n;i++)
     50         {
     51             if(bin_search(a[i]+y))
     52             {
     53                 flag2=1;
     54                 break;
     55             }
     56         }
     57         if(flag1&&flag2)
     58         {
     59             printf("0
    ");
     60         }
     61         else
     62         {
     63             if(flag1)
     64             {
     65                 printf("1
    %d
    ",y);
     66             }
     67             else if(flag2)
     68             {
     69                 printf("1
    %d
    ",x);
     70             }
     71             else
     72             {
     73                 for(i=1;i<=n;i++)
     74                 {
     75                     if(bin_search(a[i]+x+y))
     76                     {
     77                         flag1=1;
     78                         break;
     79                     }
     80                 }
     81                 if(flag1)
     82                 {
     83                     printf("1
    %d
    ",a[i]+x);
     84                 }
     85                 else
     86                 {
     87                     for(i=1;i<=n;i++)
     88                     {
     89                         if(bin_search(a[i]+y-x))
     90                         {
     91                             if(a[i]-x>=0)
     92                             {
     93                                 printf("1
    %d
    ",a[i]-x);
     94                                 flag1=1;
     95                                 break;
     96                             }
     97                             else if(a[i]+y<=l)
     98                             {
     99                                 printf("1
    %d
    ",a[i]+y);
    100                                 flag1=1;
    101                                 break;
    102                             }
    103                         }
    104                     }
    105                     if(!flag1)
    106                     {
    107                         printf("2
    %d %d
    ",x,y);
    108                     }
    109                 }
    110             }
    111         }
    112     return 0;
    113 }
    View Code
    2
    185 230

    Note

    In the first sample it is impossible to initially measure the distance of 230centimeters. For that it is enough to add a 20 centimeter mark or a 230 centimeter mark.

    In the second sample you already can use the ruler to measure the distances of 185 and230 centimeters, so you don't have to add new marks.

    In the third sample the ruler only contains the initial and the final marks. We will need to add two marks to be able to test the children's skills.

    尺子题  数学题  考虑多种情况 代码是百度的

  • 相关阅读:
    LINUX查看进程开始时间、结束时间、运行时间
    excel字符处理函数
    oracle RMAN参数配置详解
    Linux添加双IP
    免费软电话 — XLite 的安装及配置向导
    Asterisk实现寻呼对讲广播的Page()命令详解
    自动化工具的重要性
    负载均衡之应用请求路由模块的使用(ARR)(七)[使用ARR来实现主机名共享]
    负载均衡之应用请求路由模块的使用(ARR)(二)[安装]
    需求管理随笔
  • 原文地址:https://www.cnblogs.com/dulute/p/7272546.html
Copyright © 2020-2023  润新知