• hust新人赛模拟 20150407 H


    H - H
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
    Submit Status

    Description

    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 nmarks, 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 the i-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 ≤ 1052 ≤ 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). Number pi 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.

    Sample Input

    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
    2
    185 230

    Hint

    In the first sample it is impossible to initially measure the distance of 230 centimeters. 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 and 230 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.

    题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。

    一开始没有看清题目,以为答案最多为4,但是发现,a[1]=0 a[n]=l这两个是确定的,所以答案最多为2,

    而不会出现中间有两个刻度,无论是往前刻还是往后都会越界的情况。

    先去看看已知的刻度里有没有直接满足的。

    除此之外,如果在已知的刻度下无法测量x也无法测量y,我们还可以找找是否能有公用点使得只刻一个刻度就可以满足题意。公用点分两种情况,一种是在两个刻度之间,另一种是在两个刻度的同侧。

    前一种没什么坑,后一种要判断是否越界!!!

    如果在已知的刻度下能测量x或者能测量出y但不能同时测量的话,就没有必要找公用点。

    还有就是查找的话如果线性找复杂度是O(n2),会TLE在第27个点。

    我们用二分...

    话说STL里竟然连二分查找也有。。。。简直orz。。。。真是省时省力。

    代码:

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    
    using namespace std;
    
    int n,l,x,y;
    const int N=1E5+7;
    int a[N];
    int ans,p,q;
    bool flag1,flag2,flag3,flag4;
    
    int main()
    {
        scanf("%d %d %d %d",&n,&l,&x,&y);
        flag1 = false;
        flag2 = false;
        flag3 = false;
        flag4 = false;
    
        for ( int i = 1 ; i <= n ; i++ )
            scanf("%d",&a[i]);
            ans = 2;
            p = -1;
            q = 0;
        for ( int i = 1 ; i <= n ; i++ )
        {
            if(binary_search(a,a+n+1,a[i]+x))
            {
                flag1 = true;
    
            }
            if (binary_search(a,a+n+1,a[i]+y))
            {
                flag2 = true;
            }
            if (binary_search(a,a+n+1,a[i]+x+y))
            {
                flag3 = true;
                p = a[i];
            }
            if (binary_search(a,a+n+1,a[i]+y-x)&&((a[i]+y<=l)||(a[i]-x>=0)))
            {
                flag4 = true;
                p = a[i];
            }
        }
    
            if ( flag1) {ans--;q = 1 ;}
            if ( flag2 ){ ans--;q = 2 ;}
            if ( ans==2&&(flag3||flag4))
            {
                ans--;
            }
            cout<<ans<<endl;
        if ( ans==2 )
        {
            cout<<a[1]+x<<" "<<a[1]+y<<endl;
        }
        if ( ans==1 )
        {
            if ( p==-1 )
            {
                if ( q==1 )
                    cout<<a[1]+y<<endl;
                else cout<<a[1]+x<<endl;
            }
            else
            {
                if ( p+y<=l )
                cout<<p+y<<endl;
                else cout<<p-x<<endl;
            }
        }
        return 0;
    }
  • 相关阅读:
    [Django]Windows下Django配置Apache示范设置
    《职场》笔记20061119
    Python Django还是RoR,这是一个问题
    收集证据:fsjoy.com的流氓推广和幕后流氓主子[updated]
    爱尔兰网友邀请我对Dublin交通监视器进行手机端开发
    {基于Applet的J2ME模拟器}和{microemulator}[J2ME推荐]
    中国移动IM飞信0802上线新版本 试用手记
    [AsyncHandle]什么引发了ObjectDisposedException?
    百度的“搜索背后的人”的战略
    [Python]检查你的站点的人气
  • 原文地址:https://www.cnblogs.com/111qqz/p/4403477.html
Copyright © 2020-2023  润新知