Codeforces Round #274 (Div. 1) B. Long Jumps 数学

时间:2022-05-28 18:21:00

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 &num;274 &lpar;Div&period; 2&rpar;

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

  2. Codeforces Round &num;274 &lpar;Div&period; 1&rpar; C&period; 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 &num;274 &lpar;Div&period; 1&rpar; A&period; Exams 贪心

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

  4. codeforces水题100道 第八题 Codeforces Round &num;274 &lpar;Div&period; 2&rpar; A&period; Expression &lpar;math&rpar;

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

  5. Codeforces Round &num;274 &lpar;Div&period; 2&rpar;-C&period; Exams

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

  6. Codeforces Round &num;274 &lpar;Div&period; 2&rpar; 解题报告

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

  7. Codeforces Round &num;274 Div&period;1 C Riding in a Lift --DP

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

  8. Codeforces Round &num;274 &lpar;Div&period; 2&rpar; E&period; 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 &num;274 &lpar;Div&period; 2&rpar; --A Expression

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

随机推荐

  1. JQuery记住用户名和密码的具体实现

    代码如下: //初始化页面时验证是否记住了密码 $(document).ready(function() { if ($.cookie("rmbUser") == "tr ...

  2. quantile normalization原理

    对于芯片或者其它表达数据来说,最常见的莫过于quantile normalization啦. 那么它到底对我们的表达数据做了什么呢?首先要么要清楚一个概念,表达矩阵的每一列都是一个样本,每一行都是一个 ...

  3. Maven使用笔记(一)Maven安装及常用命令

    1.Windows下安装Maven 首先去下载Maven安装包,http://maven.apache.org/download.cgi,目前最新版本是 Maven 3.2.3 . 解压到本地,可以看 ...

  4. Bootstrap-基于jquery的bootstrap在线文本编辑器插件Summernote

    Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...

  5. 在iframe里调用parent&period;func&lpar;&rpar;引出的js函数运行在它们被定义的作用域里&comma;而不是它们被执行的作用域里

    有个document里定义了一个函数func(),同时在document里嵌入了一个iframe,在这个iframe里调用父窗口的方法:parent.func(),本来我以为这个函数的运行环境是在这个 ...

  6. jquery 学习笔记二 隐藏与显示

    css找到元素后是添加样式,而jquery找到元素后是添加形为. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional// ...

  7. Jquery 方法大全

    一.JQuery常用的方法 :(JQuery中90%都是方法,没有参数是获取,带参数是设置) $("#id").css('backgroundColor','blue'); .cs ...

  8. PAT乙级1006&period; 换个格式输出整数 &lpar;15&rpar;

    让我们用字母B来表示“百”.字母S表示“十”,用“12...n”来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个“百”. ...

  9. Hadoop学习笔记五

    一.uber(u:ber)模式 MapReduce以Uber模式运行时,所有的map,reduce任务都在一个jvm中运行,对于小的mapreduce任务,uber模式的运行将更为高效. uber模式 ...

  10. 模拟ios应用加载页面

    1:设置应用程序系统主界面加载接口为空:Main interface=null; 2: 在AppDelegate实现didFinishLaunchingWithOptions方法 - (BOOL)ap ...