题目链接:

B. 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 = 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 nlxy (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 题意: 现在有个长为l的尺子,上面有n个标记,现在要量两个长度x和y,问最小加几个标记才可以;分别加在哪; 思路: 最多要加两个标记,如果有标记恰好间隔x,y那么就可以直接量了,如果有一个可以量,那么再加另外一个就好了,要是两个都不能量,但加一个可以量两个,那么加一个就好,否则加两个,判断就用map; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=5e3+10;
const double eps=1e-12; int n;
LL l,x,y,a[N];
map<LL,int>mp;
int check1(LL d)
{
for(int i=1;i<=n;i++)
{
LL temp=a[i]+d;
if(mp[temp])return 1;
}
return 0;
}
int check2()
{ for(int i=1;i<=n;i++)
{
LL temp=a[i]+x+y;
if(mp[temp])
{
cout<<"1\n";
cout<<a[i]+x<<endl;
return 0;
}
}
LL leng=y-x;
for(int i=1;i<=n;i++)
{
LL temp=a[i]+leng;
if(mp[temp])
{
if(temp+x<=l){cout<<"1\n";cout<<temp+x<<endl;return 0;}
if(a[i]-x>=0){cout<<"1\n";cout<<a[i]-x<<endl;return 0;}
}
}
cout<<"2"<<endl;
cout<<x<<" "<<y<<endl;
return 0;
}
int main()
{
read(n);read(l);read(x);read(y);
For(i,1,n)read(a[i]),mp[a[i]]=1;
int fx=check1(x),fy=check1(y);
if(fx&&fy)cout<<"0\n";
else if(fx||fy)
{
if(fx)cout<<"1\n"<<y<<endl;
else cout<<"1\n"<<x<<endl;
}
else check2(); return 0;
}

  

codeforces 480B B. Long Jumps(贪心)的更多相关文章

  1. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  2. [Codeforces 1214A]Optimal Currency Exchange(贪心)

    [Codeforces 1214A]Optimal Currency Exchange(贪心) 题面 题面较长,略 分析 这个A题稍微有点思维难度,比赛的时候被孙了一下 贪心的思路是,我们换面值越小的 ...

  3. Codeforces 480B Long Jumps 规律题

    题目链接:点击打开链接 题意: 输出n l x y 有一根直尺长度为l 上面有n个刻度. 以下n个数字是距离开头的长度(保证第一个数字是0,最后一个数字是l) 要使得 直尺中存在某2个刻度的距离为x ...

  4. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  5. Codeforces Gym 100269E Energy Tycoon 贪心

    题目链接:http://codeforces.com/gym/100269/attachments 题意: 有长度为n个格子,你有两种操作,1是放一个长度为1的东西上去,2是放一个长度为2的东西上去 ...

  6. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

  7. codeforces 803D Magazine Ad(二分+贪心)

    Magazine Ad 题目链接:http://codeforces.com/contest/803/problem/D ——每天在线,欢迎留言谈论. 题目大意: 给你一个数字k,和一行字符 例: g ...

  8. Codeforces 980E The Number Games 贪心 倍增表

    原文链接https://www.cnblogs.com/zhouzhendong/p/9074226.html 题目传送门 - Codeforces 980E 题意 $\rm Codeforces$ ...

  9. Codeforces 798D Mike and distribution - 贪心

    Mike has always been thinking about the harshness of social inequality. He's so obsessed with it tha ...

随机推荐

  1. Python on VS Code

    install python extension Press F1, and input "ext install python". Then the icon at the le ...

  2. 搭建angularjs API文档站点

    提供一个国内可以访问的 angularjs API文档站点 http://i.frllk.com/ 文档直接在 github 上下载的: https://github.com/angular-cn/n ...

  3. .net经验积累

    希望对.net编程者有所帮助 1.学会配置环境变量  1.我的电脑-属性-环境变量-双击下面的path-粘贴路径  2.ctrl+r 输入软件名字按回车 2.常用vs2010快捷键  代码格式化:ct ...

  4. Plug-in 'org.eclipse.cdt.ui' contributed an invalid Menu Extension

    终于在mac上配置了最新的eclipse和adt(Win和Mac oxs通用),然后就Error Log报这种错误,运行了hello word,没有影响,但是依旧有这种错误! 记录下错误: eclip ...

  5. Android底部TabHost API

    今天在项目中遇到了底部TabHost,顺便就写了一个底部TabHost的api继承即可使用非常简单,以下为源代码: 首先是自定义的TabHostActivity,如果要使用该TabHost继承该类即可 ...

  6. iOS Xcode7上真机调试

    在Xcode7上进行真机调试,不需要证书,步骤如下: 1. 2. 3. 4. 5.添加Apple ID后会显示两个Free,表示可以免费真机调试iOS应用和Mac应用,选中高亮选项,点击view de ...

  7. 比较好用的web打印控件——Lodop

    前一段时间公司一项目比较特殊,客户要求打印单必须是淘宝上卖的那种三联打印单.如果还是使用原来系统自带的打印的话,就会造成无法打印出来理想的效果,于是找了下相关的打印控件,比较网络上比较流行的几款插件, ...

  8. windows 编程中的常见bug

    错误 1 :   error LNK2001: 无法解析的外部符号 _WTSQueryUserToken@8 解决办法:   ——>查看链接器->输入->附加依赖项,依照debug模 ...

  9. 3.输入三个整数,xyz,最终以从小到大的方式输出。利用嵌套。

    <body>请输入a的值:<input type="numbe" id="a" value=""/>请输入b的值:& ...

  10. linux下批量修改存有超大数据量IP文件中的IP内容以及去重排序

    作为一个linux的学徒,分享一下自己解决这个小问题的心得,在处理这个问题时使用了一个小技巧感觉很适用,个人发觉linux的终端真滴是非常强大,下面就详细地介绍这个问题以及解决办法吧 问题描述:由于要 ...