Long Jumps CodeForces - 479D
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.
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.
Examples
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
Note
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.
OJ-ID:
CodeForces-479D
author:
Caution_X
date of submission:
20191109
tags:
二分,贪心
description modelling:
有一把尺子,尺子上有n个刻度A[i],问能否通过已知的刻度测出长度x和长度y?
输出需要补充的刻度点个数和对应的值
major steps to solve it:
需要补充的刻度点数只能是0,1,2
需要补充的点数为0时可以直接判断
判断能否只补充一个刻度点:①记tx=A[i]+x,表示可以在A[i]右边得出一个刻度能够测出x
再二分查找判断(tx+y)或者(tx-y)在不在已知刻度中,若在,则一个刻度点tx即可,同理,②记ty=A[i]+y,
重复类似①的操作,只要①,②有一个满足条件即可,若都不满足时:记tx=A[i]-x,表示能够在
刻度点A[i]左边找到一个刻度点测出x,记ty=A[i]-y,同理操作。若通过上述操作能够找出,则
只需要补充一个刻度点,否则,需要补充两个刻度点。
warnings:
重点在于点数1和点数2的判断,点数1需要特判
比如x=6,y=7,已知的刻度点有4,5,那么只要补充一个刻度点11即可
AC code:
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn = 1e5+;
int N, L, X, Y, A[maxn]; bool judge (int u) {
if (u < || u > L) return false;
int k = lower_bound(A, A + N, u) - A;
return u == A[k];
} void solve () {
int ans = ;
for (int i = ; i < N; i++) {
if (judge(A[i] - X) || judge(A[i] + X))
ans |= ;
if (judge(A[i] - Y) || judge(A[i] + Y))
ans |= ;
} if (ans == )
printf("0\n");
else if (ans == )
printf("1\n%d\n", X);
else if (ans == )
printf("1\n%d\n", Y);
else { for (int i = ; i < N; i++) {
int tx = A[i] + X;
int ty = A[i] + Y; if (tx <= L && (judge(tx - Y) || judge(tx + Y))) {
printf("1\n%d\n", tx);
return;
} if (ty <= L && (judge(ty - X) || judge(ty + X))) {
printf("1\n%d\n", ty);
return;
}
} for (int i = ; i < N; i++) {
int tx = A[i] - X;
int ty = A[i] - Y; if (tx >= && (judge(tx - Y) || judge(tx + Y))) {
printf("1\n%d\n", tx);
return;
} if (ty >= && (judge(ty - X) || judge(ty + X))) {
printf("1\n%d\n", ty);
return;
}
}
printf("2\n%d %d\n", X, Y);
}
} int main () {
scanf("%d%d%d%d", &N, &L, &X, &Y);
for (int i = ; i < N; i++)
scanf("%d", &A[i]);
solve();
return ;
}
Long Jumps CodeForces - 479D的更多相关文章
- Codeforces 479D - Long Jumps
479D - Long Jumps, 480B - Long Jumps It , or . If we can already measure both x and y, output . Then ...
- 【Codeforces 479D】Long Jumps
[链接] 我是链接,点我呀:) [题意] 如果存在a[j]-a[i]=d 那么认为可以量出来长度d 现在给你量尺上的n个点. 问你最少要加多少个点,才能够量出来长度x和长度y [题解] 设dic1和d ...
- Discrete Centrifugal Jumps CodeForces - 1407D 单调栈+dp
题意: 给你n个数hi,你刚开始在第1个数的位置,你需要跳到第n个数的位置. 1.对于i.j(i<j) 如果满足 max(hi+1,-,hj−1)<min(hi,hj) max(hi,hj ...
- 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 480B B. Long Jumps(贪心)
题目链接: B. Long Jumps time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps
我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...
- 【codeforces 791D】 Bear and Tree Jumps
[题目链接]:http://codeforces.com/contest/791/problem/D [题意] 你可以从树上的节点一次最多走k条边. (称为跳一次); 树为无权树; 然后问你任意两点之 ...
- Codeforces 1500F - Cupboards Jumps(set)
Codeforces 题面传送门 & 洛谷题面传送门 nb tea!!!111 首先很显然的一件事是对于三个数 \(a,b,c\),其最大值与最小值的差就是三个数之间两两绝对值的较大值,即 \ ...
- CodeForces 771C Bear and Tree Jumps 树形DP
题意: 给出一棵树,一个人可以在树上跳,每次最多跳\(k(1 \leq k \leq 5)\)个点 定义\(f(s,t)\)为从顶点\(s\)跳到顶点\(t\)最少需要跳多少次 求\(\sum\lim ...
随机推荐
- 浮点运算与boost.multiprecision
在C++中,float占4个字节,double占8个字节,均采用 IEEE 754 浮点标准:内部都是以二进制为基础,表述实数,有些实数可以被精确表述,比如0.2,但有些不行,比如0.3.针对这一点, ...
- Flask的session
### session:1. session的基本概念:session和cookie的作用有点类似,都是为了存储用户相关的信息.不同的是,cookie是存储在本地浏览器,session是一个思路.一个 ...
- 《DevOps实践:驭DevOps之力强化技术栈并优化IT运行》
DevOps实践:驭DevOps之力强化技术栈并优化IT运行 主旨 这本书并非坐而论道,而是介绍了DevOps全流程中的许多实践,以及相应工具的运用.虽然随着时代的推移,工具将来可能会过时,但是这些实 ...
- Codeforces Round #607 (Div. 1)
A. Cut and Paste 题解 在计算答案的时候,我们发现只需要知道这个字符串前\(l\) 个具体是啥就行了.所以对于每一组询问,我们暴力把这个字符串前\(l\) 的位都算出来,然后剩下的就推 ...
- 【RTOS】基于V7开发板的最新版uCOS-II V2.92.16程序模板,含MDK和IAR,支持uC/Probe
模板下载: 链接:https://pan.baidu.com/s/10a9Hi0MD14obR_B1LAQEFA 提取码:z76n 1.MDK使用MDK5.26及其以上版本. 2.IAR使用I ...
- IT兄弟连 HTML5教程 CSS3揭秘 CSS3概述
对于Web开发者来说,CSS3不只是一门新奇的技术,更重要的是这些全新概念的Web应用给开发人员带来了无限的可能性,也极大地提高了开发效率.我们不必再依赖图片或者JavaScript去完成圆角.多背景 ...
- Git错误:error:failed to push some refs to 'git@gitee.com:name/project.git'
大家在通过本地仓库上传文件到远程仓库时,会报出 error:failed to push some refs to 'git@gitee.com:name/project.git' 的错误. 解决方法 ...
- 简约工作汇报总结演讲辩论创业投资PPT模板
不管是什么风格的PPT模板,排版布局条例清新,画面干净,也会跟文字内容相辅相成,完成一个好的学生答辩PPT. 模版来源:http://ppt.dede58.com/gongzuohuibao/262 ...
- ubuntu18.10 上安装docker容器
网上有的安装步骤太复杂,并且安装过程中容易出错,其它安装不难,只需一条命令即可. 安装成功后,使用命令查看docker状态 systemctl status docker 安装前更新下包源 sudo ...
- Cobalt Strike系列教程第五章:截图与浏览器代理
Cobalt Strike系列教程分享如约而至,新关注的小伙伴可以先回顾一下前面的内容: Cobalt Strike系列教程第一章:简介与安装 Cobalt Strike系列教程第二章:Beacon详 ...