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.

Sample test(s)
input
2 300 185 230
0 300
output
2
185 230
题目意思就是说:

体育课要考试,一老师拿了一把长度为l的尺子,尺子上标有一些刻度,他要求女生能跳x,男生能跳y(y>x).但是这些刻度不一定能满足测量的要求,告诉你这些刻度,让你判断一下最多需要添加几个点。理解题意很重要,有几点需要注意一下。

1.一共只需要两个刻度,所以需要的点数只有0,1,2三种可能。

2.所需要的刻度也可以由ai-aj得到。

3.多组解符合情况输出任何一组都可以。

个人心得:made做了一早上set,啥的全用了,该考虑的跨界问题也解决了,就是二重循环把时间卡死了,很无奈,后面看了大神们二分查找才知道,看来得找个机会去看看这个函数的原理啥的。

题解:

题目看起来是很简单的,但是却又感觉无从下手。先来分析一下所有情况:

1.两个距离都能找到,存在某几个点之间距离差恰好等于x,y,添加0个点;

2.只能找到一个距离x或y,添加1个点;

3.一个都找不到,但是两个点能共用一个点,只需添加一个公用点。共用一个点的话有两种情况,一种是公用点在三点中间,则能在原刻度上找到两个点使两点间距离满足x+y,另一种情况是公用点在两边,则能在原刻度上找到两个点间距离满足y-x,这种情况在左右添加公共点都可以,但是一定注意不要越过边界。此时添加1个点;

4.其他,添加2个点;

情况分析好了之后就很简单了,从前向后遍历,找四个距离,根据查找结果输出答案就好了。因为只差照一次就可以,所以时间上也快了很多。但是有一点需要注意,x,y,x+y都没问题,只要能找到一定能符合情况,但y-x就需要另外判断一下,只满足差值但是往两边添加点时却有可能越界。一定要在查找的时候去判断,比如有两组点满足差值为y-x,如果你在查找到第一组时就跳出,可能第一组是两边都会越界的,此时第二组右边虽然一定越界但左边却可能会满足,所以一定要放在查找的时候去判断。因为这个点wa了无数次,一定要注意。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,l,x,y;
int ch[];
int findr(int ans);
void solve()
{
int r1=findr(x),r2=findr(y),r3=findr(x+y),r4=findr(y-x);
if(r1!=-&&r2!=-) cout<<""<<endl;
else if(r1!=-) cout<<""<<endl<<y<<endl;
else if(r2!=-) cout<<""<<endl<<x<<endl;
else
{
if(r4!=-) cout<<""<<endl<<r4<<endl;
else if(r3!=-) cout<<""<<endl<<r3<<endl;
else if(r3==-&&r4==-)
cout<<""<<endl<<x<<" "<<y<<endl;
}
}
int findr(int ans)
{
int t;
for(int i=;i<n;i++)
{ t=lower_bound(ch,ch+n,ch[i]+ans)-ch;
if(t==n)
break;
else
{
if(ch[t]==ch[i]+ans)
{
if(ans==y-x)
{
if(ch[t]-y<&&ch[t]+x>l) continue;
else if(ch[t]-y>=) return ch[t]-y;
else return ch[t]+x;
}
else if(ans==x+y) return ch[t]-y;
else
return ;
}
}
}
return -;
}
int main()
{ cin>>n>>l>>x>>y;
for(int i=;i<n;i++)
cin>>ch[i];
solve();
return ;
}

Long Jumps(二分查找lower_bound()函数的运用)的更多相关文章

  1. STL中的二分查找———lower_bound,upper_bound,binary_search

    关于STL中的排序和检索,排序一般用sort函数即可,今天来整理一下检索中常用的函数——lower_bound , upper_bound 和 binary_search . STL中关于二分查找的函 ...

  2. LeetCode:Search Insert Position,Search for a Range (二分查找,lower_bound,upper_bound)

    Search Insert Position Given a sorted array and a target value, return the index if the target is fo ...

  3. STL中的二分查找——lower_bound 、upper_bound 、binary_search

    STL中的二分查找函数 1.lower_bound函数 在一个非递减序列的前闭后开区间[first,last)中.进行二分查找查找某一元素val.函数lower_bound()返回大于或等于val的第 ...

  4. 41、用Python实现一个二分查找的函数

    data = [1, 3, 6, 7, 9, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 33, 35] def binary_search(dataset ...

  5. STL 二分查找三兄弟(lower_bound(),upper_bound(),binary_search())

    一:起因 (1)STL中关于二分查找的函数有三个:lower_bound .upper_bound .binary_search  -- 这三个函数都运用于有序区间(当然这也是运用二分查找的前提),以 ...

  6. C++中lower_bound函数和upper_bound函数

    STL中关于二分查找的函数有三个lower_bound .upper_bound .binary_search .这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两个函数. ...

  7. STL中的二分查找

    本文转载于https://blog.csdn.net/riba2534/article/details/69240450 使用的时候注意:必须用在非递减的区间中 二分查找的原理非常简单,但写出的代码中 ...

  8. lower_bound()函数,upper_bound()函数

    1.查找:STL中关于二分查找的函数有三个lower_bound .upper_bound .binary_search .这三个函数都运用于有序区间(当然这也是运用二分查找的前提),下面记录一下这两 ...

  9. 【学习记录】二分查找的C++实现,代码逐步优化

    二分查找的思想很简单,它是针对于有序数组的,相当于数组(设为int a[N])排成一颗二叉平衡树(左子节点<=父节点<=右子节点),然后从根节点(对应数组下标a[N/2])开始判断,若值& ...

随机推荐

  1. CSS清除浮动使父级元素展开的三个方法

    点评:一个没有设置高度的容器div内如果存在浮动元素(即使用了属性float:left或者float:right),那么该父级元素会无法展开,下面举个例子为大家详细介绍下,希望对大家有所帮助 一个没有 ...

  2. 【渗透神器系列】Fiddler (收藏)

    发表于 2017-04-27   |   分类于 安全工具   |     |   阅读次数 593 人世起起落落 左手边上演的华灯初上 右手边是繁华落幕的星点余光 本篇作为渗透神器系列第二篇,将介绍 ...

  3. Loadrunder常见问题汇总(持续更新)

    1.LR 脚本为空的解决方法: 1)如果安装了IE以外的浏览器,并且IE不是默认浏览器,则无法生成录制脚本 2)如果录制脚本时IE不能打开,则需要将浏览器的IE工具高级选项中,将“启用第三方浏览器扩展 ...

  4. 转:Windows下USB接口驱动技术(二)

  5. TIJ读书笔记02-控制执行流程

      TIJ读书笔记02-控制执行流程 TIJ读书笔记02-控制执行流程 if-else 迭代 无条件分支 switch语句 所有条件语句都是以条件表达式的真假来决定执行路径,也就是通过布尔测试结果来决 ...

  6. Python编程-多线程

    一.python并发编程之多线程 1.threading模块 multiprocess模块的完全模仿了threading模块的接口,二者在使用层面,有很大的相似性,因而不再详细介绍 1.1 开启线程的 ...

  7. h5新特性 File API详解

    之前一直觉得h5的新特性就是一些新标签呢,直到想研究一下图片上传预览的原理,才发现还是有好多新的api的,只是不兼容ie低版本,挺可惜的, File API在表单中文件输入字段基础上,又添加了一些直接 ...

  8. 写makefile时候的cc和gcc

    Linux 下 的 cc 和 gcc     Linux 下 的 cc 和 gcc 周银辉 在Linux下一会看到cc,另一会又看到gcc,感觉又点混乱的样子.它们是同一个东西么,有啥区别呢 一分为二 ...

  9. 如何去掉Intellij IDEA过多的警告 设置警告级别

    Intellij IDEA的代码提示系统很强大,根据严格的代码规范,包括简洁程度,运行效率,潜在bug提前发现等等给你做出了除编译器之外的大量额外提示.但这些提示有时会给我们带来困扰,比如弄的界面很乱 ...

  10. 深入Spring:自定义注解加载和使用

    前言 在工作中经常使用Spring的相关框架,免不了去看一下Spring的实现方法,了解一下Spring内部的处理逻辑.特别是开发Web应用时,我们会频繁的定义@Controller,@Service ...