Codeforces Round #274 (Div. 2) d Long Jumps
2014-10-21 20:47
447 查看
点击打开链接链接
D. Long Jumps
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 leasty (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.
Sample test(s)
input
output
input
output
input
output
Note
In the first sample it is impossible to initially measure the distance of 230 centimeters. For that it is enough to add a20 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
D. Long Jumps
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 leasty (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.
Sample test(s)
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 2300 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 a20 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
#include<cstdio> #include<cstring> int a[111111]; int n; bool bin_search(int x) { int l,r,mid; l=1; r=n; while(l<=r) { mid=(l+r)>>1; if(a[mid]<x) l=mid+1; else if(a[mid]>x) r=mid-1; else return 1; } return 0; } int main() { int l,x,y; int i; bool flag1,flag2; scanf("%d%d%d%d",&n,&l,&x,&y); for(i=1;i<=n;i++) scanf("%d",&a[i]); flag1=flag2=0; for(i=1;i<=n;i++) { if(bin_search(a[i]+x)) { flag1=1; break; } } for(i=1;i<=n;i++) { if(bin_search(a[i]+y)) { flag2=1; break; } } if(flag1&&flag2) { printf("0\n"); } else { if(flag1) { printf("1\n%d\n",y); } else if(flag2) { printf("1\n%d\n",x); } else { for(i=1;i<=n;i++) { if(bin_search(a[i]+x+y)) { flag1=1; break; } } if(flag1) { printf("1\n%d\n",a[i]+x); } else { for(i=1;i<=n;i++) { if(bin_search(a[i]+y-x)) { if(a[i]-x>=0) { printf("1\n%d\n",a[i]-x); flag1=1; break; } else if(a[i]+y<=l) { printf("1\n%d\n",a[i]+y); flag1=1; break; } } } if(!flag1) { printf("2\n%d %d\n",x,y); } } } } return 0; }
相关文章推荐
- 【Codeforces Round 274 (Div 2)D】【STL-SET 讨论】Long Jumps 刻度尺最多加几个刻度使得可以测量X与Y
- Codeforces Round #274 (Div. 2)D. Long Jumps
- Codeforces Round #274 (Div. 2) D. Long Jumps
- Codeforces Round #274 (Div. 2) 解题报告 (C D E)
- Codeforces Round #274 (Div. 2) A,B,C
- Codeforces Round #274(Div2) B. Towers 贪心
- codeforces round 274 div2
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
- Codeforces Round #274 (Div. 2) B. Towers
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
- Codeforces Round #274 (Div. 2)E. Riding in a Lift
- 【Codeforces Round 274 (Div 2)A】【暴力 水题】Expression 三个数值运算使得结果最大
- Codeforces Round #274 (Div. 1) A. Exams 贪心
- Codeforces Round #274 (Div. 2) ——A、Expression
- Codeforces Round #274 (Div. 2)-C. Exams
- 【Codeforces Round 274 (Div 2)B】【贪心】Towers 若干次移数后使得最大差值尽可能小
- Codeforces Round #274 (Div. 2) E题:Riding in a Lift(DP)
- 【Codeforces Round 274 (Div 2)C】【贪心】Exams a[i]位置写a[i]或b[i] 所有位置的数保证不下降的最早结束时间
- Codeforces Round #274 (Div. 2)——B、Towers
- Codeforces Round #274 (Div. 2)