#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre(){freopen("c://test//input.in","r",stdin);freopen("c://test//output.out","w",stdout);}
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1,class T2>inline void gmax(T1 &a,T2 b){if(b>a)a=b;}
template <class T1,class T2>inline void gmin(T1 &a,T2 b){if(b<a)a=b;}
const int N=0,M=0,ms63=1061109567;
int n,m;
LL X,Y;
set<int>sot;
int main()
{
while(~scanf("%d%d%lld%lld",&n,&m,&X,&Y))
{
sot.clear();
for(int i=1;i<=n;++i)
{
int x;scanf("%d",&x);
sot.insert(x);
}
bool findX=0;
bool findY=0;
int Together=0;
for(set<int>::iterator it=sot.begin();it!=sot.end();++it)
{
int x=*it;
if(sot.count(x+X))findX=1;
if(sot.count(x+Y))findY=1;
if(sot.count(x+X+Y))Together=x+X;
else if(sot.count(x+Y-X)&&x+Y<=m)Together=x+Y;
else if(sot.count(x-Y+X)&&x-Y>=0)Together=x-Y;
}
if(findX&&findY){puts("0");continue;}
int ans=0;
if(findX)ans=Y;
else if(findY)ans=X;
else if(Together)ans=Together;
if(ans)
{
puts("1");
printf("%d\n",ans);
}
else
{
puts("2");
printf("%lld %lld\n",X,Y);
}
}
return 0;
}
/*
【trick&&吐槽】
有讨论性质的问题一定不要局限在固有的方案和思维逻辑中。
一定要保证思维的严谨,不漏任何情况!
【题意】
有一个尺子,总长度为m(2<=m<=1e9)。
尺子上共有n(2<=n<=1e5)个刻度,我们按顺序告诉你所有刻度。
数据保证——第一个刻度是0,最后一个刻度是m。
我们想要测量两个长度X,Y(1<=X<Y<=m)。
问你,至少要添加几个刻度,才能实现我们的目的。并输出所有添加的刻度。
【类型】
STL-set 讨论
【分析】
这题,我们可以把所有的点就加进set中,
然后枚举一个点x,
去查找是否有x+X,是否有x+Y,如果两者都有,那么答案就是0。否则答案肯定至少为1。
再去查找是否有x+X+Y,是否有x+Y-X,如果两者有其一,那么答案就是1?
No no no。我们还要考虑实际,考虑尺子总长度只有m。
对于x+Y-X,我们是想要添加x+Y的刻度。以同时获取Y和X
然而,这个却要巴证x+Y<=m。千万不要忘记这里!
同时,我们发现,我们还需要考虑x-Y+X的位置。因为有的位置差是Y-x,向右划刻度可能会超m,但是不代表不可以向左划。
多考虑一些,就可以AC啦!
【时间复杂度&&优化】
O(nlogn)
【数据】
2 2 1 1
0 2
*/
【Codeforces Round 274 (Div 2)D】【STL-SET 讨论】Long Jumps 刻度尺最多加几个刻度使得可以测量X与Y
最新推荐文章于 2017-08-20 14:43:55 发布