题目链接:

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 2300 185 250

output
1230

input
4 250 185 2300 20 185 250

output
0

input
2 300 185 2300 300

output
2185 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;
}

  

转载于:https://www.cnblogs.com/zhangchengc919/p/5843903.html

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 671E Organizing a Race (贪心、线段树)

    题目链接 https://codeforces.com/contest/671/problem/E 题解 完全不会做--基本是抄lk的代码 ruogu的题解: https://www.luogu.co ...

  3. CodeForces - 1529E Trees of Tranquillity(贪心+线段树)

    题目链接:https://vjudge.net/problem/CodeForces-1529E 题目大意:给出两棵根节点为 111 的树,分别称为 AAA 树和 BBB 树,现在通过两棵树可以构造出 ...

  4. [CodeForces 1603C] Extreme Extension(贪心 + 数论分块优化dp)

    problem CodeForces solution observation1:\text{observation1}:observation1: 对于一个非空子段 [l,r][l,r][l,r], ...

  5. codeforces 416C C. Booking System(贪心)

    题目链接: codeforces 416C 题目大意: 给出n个请求,每个请求包括客人数量和支付金额,再给出m个桌子,包括桌子大小,问如何安排才能最大盈利.给出最大盈利和一个能够最大盈利的方案. 题目 ...

  6. Codeforces 540B School Marks 【贪心构造】

    题目链接:Codeforces 540B School Marks Little Vova studies programming in an elite school. Vova and his c ...

  7. CodeForces 508E Arthur and Brackets 贪心

    题目: E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input s ...

  8. Codeforces 797C Minimal string【贪心】

    题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后. 2.把t字符串最后一个字符转移到u字符串最后. 最后要求s.t字符串都为空,问u ...

  9. codeforces 719C (复杂模拟-四舍五入-贪心)

    题目链接:http://codeforces.com/problemset/problem/719/C 题目大意: 留坑... 转载于:https://www.cnblogs.com/A--Q/p/5 ...

最新文章

  1. 微软将发布5月安全漏洞补丁 修补PPT
  2. 腾讯最新开源IoT操作系统登上GitHub热榜,最小体积仅1.8 KB,标星1200+
  3. 对象检测和浏览器检测
  4. POJ 1047 Round and Round We Go
  5. 通过IDEA查看某个类的继承关系
  6. 2020年8月编程语言排行榜新鲜出炉 - 编程语言世界的假期
  7. 机器学习-集成学习:随机森林(Random Forest)
  8. 坚果nuts 加速 官网_【喂你播】坚果手机2020新品发布会来了;三星定向华为手机推以旧换新...
  9. 通道控制方式,通道指令与通道程序
  10. C++ 重载赋值运算符与11选5平台修复
  11. 导航器 Navigator
  12. SSH dao层异常 org.hibernate.HibernateException: No Session found for current thread
  13. selenium 配合多线程_Selenium Webdriver 远程测试和多线程并发测试
  14. 6.Docker技术入门与实战 --- Docker数据管理
  15. 软件质量与测试的新纪元
  16. 苹果cms如何添加广告代码
  17. 《信号与系统》(吴京)部分课后习题答案与解析——第二章(PART2)
  18. 好压 v6.3.11130 绿色纯净版(编程必备软件)
  19. sql 中判断身份证男女等
  20. 如何在线下载哔哩哔哩上的视频

热门文章

  1. Java 分布式 RPC 框架性能大比拼,Dubbo 排第几?
  2. 代码优化 5 大原则,第一条就是别优化了!!!
  3. 使用 ThreadLocal 一次解决老大难问题
  4. 历史上最简单的一道Java面试题,但无人能通过
  5. 如何正确访问Redis中的海量数据?服务才不会挂掉!
  6. 手把手带你用数据库中间件Mycat+SpringBoot完成分库分表
  7. MySQL:缓存算什么东西?!
  8. Intellij IDEA神器居然还有这些小技巧
  9. Thread类源码剖析
  10. 数据库:数据库的连接池原理及实现