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 ...
随机推荐
- JavaEE连接池泄漏问题检测Oracle数据库
1.项目环境 项目是典型的轻量级JavaEE项目,使用SSH框架构建,数据源使用DBCP管理,和Spring进行了整合. 项目数据库使用Oracle数据库. 项目DBCP配置内容如下 ###### D ...
- 05_Elasticsearch 单模式下API的增删改查操作
05_Elasticsearch 单模式下API的增删改查操作 安装marvel 插件: zjtest7-redis:/usr/local/elasticsearch-2.3.4# bin/plugi ...
- 系统监控的工具tsar
近期一直在折腾着elasticsearch,需要对硬件进行评估 大概几方面 内存 cpu 硬盘 网络. iostat vmstat top 几个命令用了一堆,其实需要关注的几个点只要都列出来就可以了 ...
- iOS面试知识点
1 iOS基础 1.1 父类实现深拷贝时,子类如何实现深度拷贝.父类没有实现深拷贝时,子类如何实现深度拷贝. 深拷贝同浅拷贝的区别:浅拷贝是指针拷贝,对一个对象进行浅拷贝,相当于对指向对象的指针进行复 ...
- Handsontable 新增一行 默认值
效果图:
- ubuntu下30天自制操作系统还在继续学习中
操作系统还在学习中,进度不是非常确定,近期学习到了第13天的中部,由于把ucgui移植上去花了一点时间. 同一时候为了方便代码的兴许管理和分享,也为了学习github的代码管理使用思想, 所以建立了一 ...
- iOS新的旅程之Swift语言的学习
好久都没有来这个熟悉而又陌生的地方啦, 想想已经有两三个月了吧,不过我相信以后还是会经常来的啦,因为忙碌的学习已经过去啦,剩下的就是要好好的总结好好的复习了,好好的熟悉下我们之前学习的知识点,将他们有 ...
- 15. SSH 远程
一.原理: 使用SSH连接Centos时,我们可以创建一个公钥和一个私钥,公钥放在服务端,私钥放在客户端,当客户端去连接服务端时,会先去查找密钥, 要是客户端的私钥可以和服务端的公钥匹 ...
- Log4net 列
配置 <configuration> <configSections> <section name="log4net" type="Syst ...
- Win7刷新环境变量
在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环境变量后,需重启系统才能使之生效.有没有什么方法可让它即时生效呢? 下面介绍一种方法: 以修改环境变量“PATH” ...