思路:
可以先写几组数据分析一下怎么构造解。先排序,大小为1和2就不用说了,大小为3的时候,相邻的差值一定相等且为2的幂,这样最大和最小的差值一定也是2的幂。分析大小为4的时候,如果前三个数按照以上规则构造,那么最后一个数一定构造不出来。由此可知大小最大为3。并且贪心策略也有了。这一题用map会超,可以用二分查找。
代码:
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define MAXN 200005
#define ll long long
int n,ans;
ll a[MAXN],b[10],fac[66];
int main()
{
scanf("%d",&n);
fac[0]=1;
for(int i=1;i<=63;i++)
{
fac[i]=fac[i-1]<<1;
}
for(int i=0;i<n;i++)
{
scanf("%lld",&a[i]);
}
sort(a,a+n);
ans=1;
b[0]=a[0];
for(int i=0;i<n;i++)
{
for(int j=0;j<=62;j++)
{
if(i+2<n && (*lower_bound(a,a+n,a[i]+fac[j]))==a[i]+fac[j] && (*lower_bound(a,a+n,a[i]+fac[j+1]))==a[i]+fac[j+1])
{
printf("3\n");
printf("%lld %lld %lld\n",a[i],a[i]+fac[j],a[i]+fac[j+1]);
exit(0);
}
else if(i+1<n && (*lower_bound(a,a+n,a[i]+fac[j]))==a[i]+fac[j] && ans==1)
{
ans=2;
b[0]=a[i];
b[1]=a[i]+fac[j];
}
}
}
printf("%d\n",ans);
for(int i=0;i<ans;i++)
{
if(i) printf(" ");
printf("%lld",b[i]);
}
printf("\n");
return 0;
}