B. Long Jumps

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/480/problem/B

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 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.

Sample Input

3 250 185 230
0 185 250

Sample Output

1
230

HINT

题意

给你一个尺子,上面已经有了n个刻度,这把尺子最长l,然后问你最少加几个刻度,就可以测出x和y了

题解:

答案肯定只有0,1,2这三种

答案为0的就很简单,那么就是x存在或者y存在,或者k和k+x同时存在,k和k+y也同时存在

答案为2的也很简单,就把x,y直接输出就好了

答案为1的讨论一下:

1.x或者y其中一个可以由尺子构成

2.尺子上存在k-x-y,那么我们可以构造一个k-x或者k-y就行了

3.尺子上存在k-(y-x),那么我们可以构造k+x,或者k-y就行了

代码:

#include<iostream>
#include<stdio.h>
#include<map>
using namespace std;
#define maxn 100005
map<int,int> H;
int main()
{
int n,l,x,y;
scanf("%d%d%d%d",&n,&l,&x,&y);
if(x>y)swap(x,y);
int flag1=,flag2=,flag3=;
for(int i=;i<=n;i++)
{
int k;scanf("%d",&k);
H[k]=;
if(H[x])flag1=;
if(H[k-x])flag1=;
if(H[k+x])flag1=;
if(H[k-y])flag2=;
if(H[k+y])flag2=;
if(H[y])flag2=;
if(H[k-x-y])flag3=k-x;
if(H[k-(y-x)])
{
if(k+x<=l)flag3=k+x;
else if(k-y>=)flag3=k-y;
}
}
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 if(flag3)printf("1\n%d\n",flag3);
else printf("2\n%d %d\n",x,y);
}

Codeforces Round #274 (Div. 1) B. Long Jumps 数学的更多相关文章

  1. Codeforces Round #274 (Div. 2)

    A http://codeforces.com/contest/479/problem/A 枚举情况 #include<cstdio> #include<algorithm> ...

  2. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  3. Codeforces Round #274 (Div. 1) A. Exams 贪心

    A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...

  4. codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)

    题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...

  5. Codeforces Round #274 (Div. 2)-C. Exams

    http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...

  6. Codeforces Round #274 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...

  7. Codeforces Round #274 Div.1 C Riding in a Lift --DP

    题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...

  8. Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)

    Imagine that you are in a building that has exactly n floors. You can move between the floors in a l ...

  9. Codeforces Round #274 (Div. 2) --A Expression

    主题链接:Expression Expression time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. 【转】./a.out 2>&1 > outfile

    原文网址:http://www.cnblogs.com/zhaoyl/archive/2012/10/22/2733418.html APUE 3.5关于重定向有个容易迷惑人的问题: ./a.out ...

  2. 常用的PL/SQL开发原则

    (1)广泛使用绑定变量,特别是批量绑定,因为这可以有效的避免sql的硬解析和PL/SQL引擎和SQL引擎的上下文切换!(2)广泛使用UROWID来处理DML语句(UROWID是ROWID扩展,ORAC ...

  3. .net-C#代码判断

    ylbtech-doc:.net-C#代码判断 C#代码判断 1.A,C#代码判断返回顶部 01.{ C#题目}public static void Main(string[] args){     ...

  4. [BILL WEI] stimulsoft 分组页眉页脚的使用

    我们在通过stimulsoft设计报表的时候,有的时候,需要做出如下图报表样式 这个时候,因为箱号是分开扩展的,我们就需要用到分组页眉了,如下图demo跟实例所示:

  5. windows各种程序中文显示乱码又找不到原因时

    我电脑上的各种程序,如xshell,Navicat for MySQL都不正常显示中文,该软件的编码,utf-8,gbk,gb2312来回切换好几回,没一次正常,最好解决办法如下       进入控制 ...

  6. CSS常用十大技巧

    技巧1  去掉网页超链接的下划线 去掉网页超链接的下划线,在<head>与</head>之间相应的位置输入以下代码. <style type="text/css ...

  7. Claim-based-security for ASP.NET Web APIs using DotNetOpenAuth

    Recently I worked with a customer assisting them in implementing their Web APIs using the new ASP.NE ...

  8. maven学习系列第二课,关于springmvc的pop.xml的依赖的添加

    不说废话了,图的书序就是操作顺序 1. 2.

  9. 关于c3p0配置详细说明

    <!-- c3p0连接池配置 --> <property name="driverClass" value="${c3p0.driverClass}&q ...

  10. C#学习1

    一.C#可以干什么? 1.桌面应用程序,WinForm 2.Internet应用程序,ASP.Net 3.手机开发,WindowsPhone8 二..Net开发学习路线 C#语言——>简单的Wi ...