cf479D Long Jumps
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 aidenotes 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.
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.
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.
3 250 185 230
0 185 250
1
230
4 250 185 230
0 20 185 250
0
2 300 185 230
0 300
2
185 230
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.
求最少要加几个数使得存在a[i]-a[j]=x,a[k]-a[l]=y
毕竟我逗比了……wa了6次之后又被x了
各种无脑二分就过了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
LL n,L,x,y;
LL a[];
bool xx,yy,xy,yx;
LL xxyy,yyxx;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline bool bsearch(LL x)
{
int l=,r=n;
while (l<=r)
{
int mid=(l+r)>>;
if (a[mid]==x)return ;
if (a[mid]<x)l=mid+;
if (a[mid]>x)r=mid-;
}
return ;
}
int main()
{
n=read();L=read();x=read();y=read();
for (int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);
for(int i=;i<=n;i++)
{
if (bsearch(a[i]+x))xx=,printf("xx %d\n",i);
if (bsearch(a[i]+y))yy=,printf("yy %d\n",i);
if (bsearch(a[i]+x+y))xy=,xxyy=a[i]+x;
if (bsearch(a[i]+y-x))
{
if(a[i]+y<=L) {yyxx=a[i]+y;yx=;}
if(a[i]-x>=) {yyxx=a[i]-x;yx=;}
}
}
if (xx&&yy)
{
printf("0\n");
}else
if (xx&&!yy)
{
printf("1\n%lld\n",y);
}else
if (yy&&!xx)
{
printf("1\n%lld\n",x);
}else
if (!xx&&!yy&&xy)
{
printf("1\n%lld\n",xxyy);
}else
if (!xx&!yy&&yx)
{
printf("1\n%lld\n",yyxx);
}else
{
printf("2\n%lld %lld\n",x,y);
}
}
cf479D
cf479D Long Jumps的更多相关文章
- codeforces 480B B. Long Jumps(贪心)
题目链接: B. Long Jumps time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #274 (Div. 1) B. Long Jumps 数学
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...
- Codeforces 479D - Long Jumps
479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...
- the quick brown fox jumps over the lazy dog
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
- [CF791D]Bear and Tree Jumps
题目描述 A tree is an undirected connected graph without cycles. The distance between two vertices is th ...
- vim使用跳转列表 jumps 来跟踪 (历史位置的)导航
参考: Vim使用跳转列表来跟踪你的导航,你可以通过这个列表来向前或者向后导航. 跳转列表保留所有地方的轨迹,它可以跟踪文件名.行号和列号. 查看调整列表::jumps 导航键 描述 CTRL-o 跳 ...
- python json (loads(),load(),jump(),jumps())
# loads() str to json data# jumps() json to str# jump() json to filedef ladstest(): data = '{"n ...
- zabbix监控cpu jumps
cpu监控图形分为三种 cpu jumps cpu突发 包含 context switches per second 进程线程切换 interrupts per second 每秒的中断次数 cpu ...
- Long Jumps(二分查找lower_bound()函数的运用)
Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long ju ...
随机推荐
- logstash 字段类型转换后 需要刷新
filter { grok { match => [ "message" , "\s*%{IPORHOST:clientip}\s+\-\s+\-\s+\[%{HT ...
- 网络版shell之网络编程练习篇--telnet服务端
网络版shell之网络编程练习篇--telnet服务端 以前写过一个shell命令解释器,对与shell命令解释器的执行流程有了清晰的认识,这段时间学习网络编程,至于网络编程的细节以及知识点,已经 ...
- Linux下串口编程入门
简介: Linux操作系统从一开始就对串行口提供了很好的支持,本文就Linux下的串行口通讯编程进行简单的介绍. 串口简介 串行口是计算机一种常用的接口,具有连接线少,通讯简单,得到广泛的使用.常用 ...
- HDOJ-1015 Safecracker(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...
- ofbiz ins
- 基础总结篇之九:Intent应用详解
看似尋常最奇崛,成如容易卻艱辛.北宋.王安石 看似普通的事情其实最不同寻常,并不是简简单单就可以做好的:成功看起来似乎很容易,而成功的过程却充满着艰辛. 对于我们认为很普通的事情,不屑一顾,就永远不会 ...
- python 弄github代码库列表
1.底 项目要求,征求github的repo的api,为了能够提取repo对数据进行分析. 研究一天.最终克服该问题,較低下. 由于github的那个显示repo的api,列出了 ...
- NET基础课--Linq第一讲
在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前,在声明一个变量的时候, 总是要为一个变量指定他的类型甚至在foreach一 ...
- a标签伪类的顺序
在一次开发项目中,我用a链接来做效果,测试的时候发现,a:hover被点击后的效果就不再了!我百度才知道,原来在css写a链接也是有顺序之分的. 顺序应该是: a:link a标签还未被访问的状态: ...
- jquery文本框验证字符长度和只能输入数字
<input type="text" class="chujia" onkeyup="this.value=this.value.replace ...