Long Jumps CodeForces - 479D

Posted cautx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Long Jumps CodeForces - 479D相关的知识,希望对你有一定的参考价值。

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 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 n, l, x, y (2 ≤ n ≤ 105, 2 ≤ l ≤ 109, 1 ≤ 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.

Examples
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
Note

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.

OJ-ID:
CodeForces-479D

author:
Caution_X

date of submission:
20191109

tags:
二分,贪心

description modelling:
有一把尺子,尺子上有n个刻度A[i],问能否通过已知的刻度测出长度x和长度y?
输出需要补充的刻度点个数和对应的值

major steps to solve it:
需要补充的刻度点数只能是0,1,2
需要补充的点数为0时可以直接判断
判断能否只补充一个刻度点:①记tx=A[i]+x,表示可以在A[i]右边得出一个刻度能够测出x
再二分查找判断(tx+y)或者(tx-y)在不在已知刻度中,若在,则一个刻度点tx即可,同理,②记ty=A[i]+y,
重复类似①的操作,只要①,②有一个满足条件即可,若都不满足时:记tx=A[i]-x,表示能够在
刻度点A[i]左边找到一个刻度点测出x,记ty=A[i]-y,同理操作。若通过上述操作能够找出,则
只需要补充一个刻度点,否则,需要补充两个刻度点。


warnings:
重点在于点数1和点数2的判断,点数1需要特判
比如x=6,y=7,已知的刻度点有4,5,那么只要补充一个刻度点11即可


AC code:

#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
const int maxn = 1e5+5;
int N, L,  X, Y, A[maxn];
 
bool judge (int u) {
    if (u < 0 || u > L) return false;
    int k = lower_bound(A, A + N, u) - A;
    return u == A[k];
}
 
void solve () {
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (judge(A[i] - X) || judge(A[i] + X))
            ans |= 1;
        if (judge(A[i] - Y) || judge(A[i] + Y))
            ans |= 2;
    }
 
    if (ans == 3)
        printf("0
");
    else if (ans == 2)
        printf("1
%d
", X);
    else if (ans == 1)
        printf("1
%d
", Y);
    else {
 
        for (int i = 0; i < N; i++) {
            int tx = A[i] + X;
            int ty = A[i] + Y;
 
            if (tx <= L && (judge(tx - Y) || judge(tx + Y))) {
                printf("1
%d
", tx);
                return;
            }
 
            if (ty <= L && (judge(ty - X) || judge(ty + X))) {
                printf("1
%d
", ty);
                return;
            }
        }
 
        for (int i = 0; i < N; i++) {
            int tx = A[i] - X;
            int ty = A[i] - Y;
 
            if (tx >= 0 && (judge(tx - Y) || judge(tx + Y))) {
                printf("1
%d
", tx);
                return;
            }
 
            if (ty >= 0 && (judge(ty - X) || judge(ty + X))) {
                printf("1
%d
", ty);
                return;
            }
        }
        printf("2
%d %d
", X, Y);
    }
}
 
int main () {
    scanf("%d%d%d%d", &N, &L, &X, &Y);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    solve();
    return 0;
}

 

以上是关于Long Jumps CodeForces - 479D的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 1324 C. Frog Jumps(贪心/二分)

箭头函数this指向

Codeforces Round #237 (Div. 2) / 404B Marathon (fmod或long long表示浮点)

Link/Cut Tree CodeForces - 614A 暴力+爆 long long 处理

Codeforces 71A Way Too Long Words

Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths