Codeforces Round #274 (Div. 2)D. Long Jumps

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 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 = 0an = 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 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 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.


题意:就是有一把尺子,长度为l,有n个刻度,问你能不能量出x和 y(x<y)的值,如果不行,就加刻度上去,最少加几个刻度上去。

 很明显就两个数最多加两个刻度上去,那么首先判断x和y能否被量出,可以是两个刻度相减,或者两个刻度相加得到x,y。那么用到了set 里的count(n) 返回n在数据集里存在的个数,因为set里的数据都是唯一的,所以返回值只有0,1。

那么遍历刻度,如果a[i]+x 存在,即表示有一个刻度P存在P-a[i]==x;如上题红色部分的解释,d只能是两个刻度相减得到,所以判断x,y是否存在的时的时候只需要判断a[i]+x,a[i]+y是否存在就好。

如果只有一个存在,加上另一个刻度就好,如果两个都不存在就要判断是否可以加一个刻度可以量出两个来,那么就要判断 一下

首先判断第一种情况,加上刻度P=a[i]+x,判断一下a[i]+x-y 或者a[i]+x+y得刻度是否存在


然后判断P=a[i]-x,判断a[i]-x+y和a[i]-x-y得刻度是否存在。

另附上几组容易出错的数据:

Input
4 300 4 5
0 6 7 300
Answer
1
11


2 100 30 70
0 100


1
30


4 300 4 5
0 298 299 300


1
294


19 180 117 148
0 1 19 20 21 28 57 65 68 70 78 88 100 116 154 157 173 179 180


2
117 148

#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;
set<int> s;
int a[111111];
int n,l;
int x,y;
int find(int x)
{
<span style="white-space:pre">	</span>for(int i=0;i<n;i++)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>if(a[i]+x<=l && s.count(a[i]+x) )return 1;
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>return 0;
}
int check()
{
<span style="white-space:pre">	</span>int i,j;
<span style="white-space:pre">	</span>for(i=0;i<n;i++)
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>if(a[i]+x<=l && (s.count(a[i]+x+y) || s.count(a[i]+x-y)))
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>//<span style="white-space:pre">	</span>cout<<"RR"<<endl;
<span style="white-space:pre">			</span>return a[i]+x;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>   if(a[i]-x>=0 && (s.count(a[i]-x+y)|| s.count(a[i]-x-y)))
<span style="white-space:pre">		</span>{
<span style="white-space:pre">		</span>//<span style="white-space:pre">	</span>cout<<"EEE"<<endl;
<span style="white-space:pre">			</span>return a[i]-x;
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>
<span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>return -1;
}
int main()
{
//<span style="white-space:pre">	</span>freopen("q.in","r",stdin);
<span style="white-space:pre">	</span>int i,j;
<span style="white-space:pre">	</span>while(~scanf("%d%d%d%d",&n,&l,&x,&y))
<span style="white-space:pre">	</span>{
<span style="white-space:pre">		</span>for(i=0;i<n;i++)
<span style="white-space:pre">		</span>{
<span style="white-space:pre">			</span>scanf("%d",&a[i]);
<span style="white-space:pre">			</span>s.insert(a[i]);
<span style="white-space:pre">		</span>}
<span style="white-space:pre">	</span>    int t1=find(x),t2=find(y);
<span style="white-space:pre">	</span>    if(t1 && t2)
<span style="white-space:pre">	</span>    {
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>cout<<"0"<<endl;
<span style="white-space:pre">	</span>    }
<span style="white-space:pre">	</span>    else if(t1 && !t2)
<span style="white-space:pre">	</span>    {
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>cout<<"1"<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>cout<<y<<endl;
<span style="white-space:pre">	</span>    }
<span style="white-space:pre">	</span>    else if(t2 && !t1)
<span style="white-space:pre">	</span>    {
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>cout<<"1"<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>cout<<x<<endl;
<span style="white-space:pre">	</span>    }
<span style="white-space:pre">	</span>    else
<span style="white-space:pre">	</span>    {
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>int res=check();
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>if(res!=-1)
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>//<span style="white-space:pre">	</span>cout<<"RRRR"<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">		</span>cout<<"1"<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">		</span>cout<<res<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>else
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>{
<span style="white-space:pre">	</span>    <span style="white-space:pre">		</span>cout<<"2"<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">		</span>cout<<x<<" "<<y<<endl;
<span style="white-space:pre">	</span>    <span style="white-space:pre">	</span>}
<span style="white-space:pre">	</span>    }
<span style="white-space:pre">	</span>}
} 


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip基于Django+python编写开发的毕业生就业管理系统支持学生教师角色+db数据库(毕业设计新项目).zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值