hust新人赛模拟 20150407 H

H - H

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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 Input

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

Hint

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.

题意是说有一把尺子,本身有一些刻度,然后需要测量x和y,问最少需要添加多少个刻度,如果需要,这些刻度分别添加在什么位置。

一开始没有看清题目,以为答案最多为4,但是发现,a[1]=0 a[n]=l这两个是确定的,所以答案最多为2,

而不会出现中间有两个刻度,无论是往前刻还是往后都会越界的情况。

先去看看已知的刻度里有没有直接满足的。

除此之外,如果在已知的刻度下无法测量x也无法测量y,我们还可以找找是否能有公用点使得只刻一个刻度就可以满足题意。公用点分两种情况,一种是在两个刻度之间,另一种是在两个刻度的同侧。

前一种没什么坑,后一种要判断是否越界!!!

如果在已知的刻度下能测量x或者能测量出y但不能同时测量的话,就没有必要找公用点。

还有就是查找的话如果线性找复杂度是O(n2),会TLE在第27个点。

我们用二分...

话说STL里竟然连二分查找也有。。。。简直orz。。。。真是省时省力。

代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int n,l,x,y;
const int N=1E5+7;
int a[N];
int ans,p,q;
bool flag1,flag2,flag3,flag4;

int main()
{
    scanf("%d %d %d %d",&n,&l,&x,&y);
    flag1 = false;
    flag2 = false;
    flag3 = false;
    flag4 = false;

    for ( int i = 1 ; i <= n ; i++ )
        scanf("%d",&a[i]);
        ans = 2;
        p = -1;
        q = 0;
    for ( int i = 1 ; i <= n ; i++ )
    {
        if(binary_search(a,a+n+1,a[i]+x))
        {
            flag1 = true;

        }
        if (binary_search(a,a+n+1,a[i]+y))
        {
            flag2 = true;
        }
        if (binary_search(a,a+n+1,a[i]+x+y))
        {
            flag3 = true;
            p = a[i];
        }
        if (binary_search(a,a+n+1,a[i]+y-x)&&((a[i]+y<=l)||(a[i]-x>=0)))
        {
            flag4 = true;
            p = a[i];
        }
    }

        if ( flag1) {ans--;q = 1 ;}
        if ( flag2 ){ ans--;q = 2 ;}
        if ( ans==2&&(flag3||flag4))
        {
            ans--;
        }
        cout<<ans<<endl;
    if ( ans==2 )
    {
        cout<<a[1]+x<<" "<<a[1]+y<<endl;
    }
    if ( ans==1 )
    {
        if ( p==-1 )
        {
            if ( q==1 )
                cout<<a[1]+y<<endl;
            else cout<<a[1]+x<<endl;
        }
        else
        {
            if ( p+y<=l )
            cout<<p+y<<endl;
            else cout<<p-x<<endl;
        }
    }
    return 0;
}
时间: 2024-10-12 11:26:50

hust新人赛模拟 20150407 H的相关文章

hust新人赛模拟20150407 A

A - A Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valer

hust新人赛模拟20150407 F

F - F Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Description Pasha got a very beautiful string s for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered

【阿里云新人赛】恶意程序检测-项目实践总结

1. 比赛信息 比赛地址:阿里云恶意程序检测新人赛 比赛介绍:使用自然语言处理的方法对恶意程序的行为(API调用序列)进行分析,实现对恶意程序鉴别及分类. 2. 我的主要工作 1)数据预处理:格式转换csv->txt->pkl,根据fileid分组数据,排序后生成api序列,用于训练: 2)数据分析及可视化:主要是数据分布分析,包括恶意程序类别分布分析.调用api的类别及频率分析,训练集与测试集分布差异分析(计算交叉熵)等, 得出结论:此任务训练集与测试集分布差异不大,恶意程序类型更多是与ap

NYOJ-682 小媛在努力 (郑大第六届校赛 模拟)

链接:click here 题意: 描述 在多媒体数据处理中,数据压缩算法尤为重要.小媛上完课后就想自己发明一个数据压缩算法.她想呀想,终于想到一个方法.在多媒体数据中有很多数据都是重复的,所以她想把连续相同的数据用数据出现的次数和数据本身表示.例如:1 1 1 2 3 3 3 3 3  压缩后及为3 1 1 2 5 3(表示3个1,1个2和5个3).有想法后小媛就希望把它用代码实现了.但是大家都知道小媛现在整天都忙着苦B的复习考研,连电脑都摸不到.所以她希望作为ACMer的你帮她写一下. 输入

【题解】PAT团体程序设计天梯赛 - 模拟赛

由于本人愚笨,最后一题实在无力AC,于是只有前14题的题解Orz 总的来说,这次模拟赛的题目不算难,前14题基本上一眼就有思路,但是某些题写起来确实不太容易,编码复杂度有点高~ L1-1 N个数求和 设计一个分数类,重载加法运算符,注意要约分,用欧几里得算法求个最大公约数即可. 1 #include <cstdio> 2 3 long long abs(long long x) 4 { 5 return x < 0 ? -x : x; 6 } 7 8 long long gcd(long

2014年北京赛区区域赛现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. 先将这五题的题解放上来,剩余题目等搞出来再补上 A题 A Curious Matt Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others) Problem Description T

关于 省赛模拟赛(迪迦桑专场)

这一次的小比赛,因为全是英文题,导致了我们队的心态有点崩,以前很少打这种全是英文的比赛, 但是我们明知道以后还会打这种比赛, 却没有提前做好准备. 这一次的比赛我们全程跟着榜单走, 我们队一开始采取了2+1的打法, 让一个人去钻一道题, 其他两个人去快速的解决一些简单的题, 然后在解决两道题之后, 变为了一人钻一题的模式, 但是依旧没有太大的突破. 这一次我写的是C题,因为一个小漏洞,导致了一直WA,最后还是没有找出来....以后多去找一些细节问题,做到下次不会再栽在这个问题上面. C - Wh

2016年 团体程序设计天梯赛 - 模拟赛

此处有目录↑ L1的题太水了,直接模拟即可,就不贴了 L3-2和L3-3没时间写了(估计也不好写吧...) 比赛网址:https://www.patest.cn/contests/2016gplt-0 交题网址: https://www.patest.cn/contests/gplt L2-1. 集合相似度 (排序) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定两个整数集合,它们的相似度定义为:Nc/Nt*100%.

模拟赛 模拟题

1.送分题(ptgiving.cpp/c/pas) [问题背景] ? 众所周知, xkj是GH的得意门生,可是 xkj的数学成绩并不是很理想,每次GH在批评完数学限训做的差的人后,总会在后面加上一句,咱们班还有一位做的最差的同学--xkj,你看看你还有对号吗,居然比cdy做得还差! xkj当然是不服的啦,当场跟GH van♂硬币.在玩完硬币后,生成了一系列随机的乱七八糟的数字,并把他们整列成科学计数法的形式,并排序成有序的序列,还计算出排序的最小成本之后,终于,从桌堂里掏出了一本古老的小黄书--