先由小到大排序
1:只有一个数 无限多
2:存在3种以上的间距 无
3:出现2种间距
大的间距只有1个,且长度是小的两倍 1种
大的间距有几个 无
4:只有1种间距
只出现一次 一头一尾 或者 加上中间
**仅有的间距是0 1种
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
using namespace std;
int n,ct=0;
int a[200200];
set<int> vis;
struct node
{
int dist,num,pos;
}D[5];
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",a+i);
}
if(n==1)
{
printf("-1\n"); return 0;
}
sort(a,a+n);
bool flag=true;
for(int i=1;i<n;i++)
{
int dd=a[i]-a[i-1];
if(vis.count(dd)==0)
{
vis.insert(dd);
D[ct].dist=dd;
D[ct].num=1;
D[ct].pos=i;
ct++;
}
else
{
for(int j=0;j<ct;j++)
{
if(D[j].dist==dd)
{
D[j].num++;
break;
}
}
}
if(ct>=3)
{
flag=false; break;
}
}
if(flag==false)
{
printf("0\n"); return 0;
}
if(ct==1&&D[0].num!=1)
{
int Dd=D[0].dist;
if(Dd!=0)
{
printf("2\n");
printf("%d %d\n",a[0]-Dd,a[n-1]+Dd);
}
else
{
printf("1\n");
printf("%d\n",a[0]);
}
return 0;
}
if(ct==1&&D[0].num==1)
{
int Dd=D[0].dist;
if(Dd)
{
if(Dd%2==0)
{
printf("3\n");
printf("%d %d %d\n",a[0]-Dd,a[0]+Dd/2,a[n-1]+Dd);
}
else
{
printf("2\n");
int Dd=D[0].dist;
printf("%d %d\n",a[0]-Dd,a[n-1]+Dd);
}
return 0;
}
else
{
printf("1\n");
printf("%d\n",a[0]);
return 0;
}
}
int dade=(D[0].dist>D[1].dist)? 0 : 1;
if(D[dade].num!=1)
{
printf("0\n"); return 0;
}
else
{
if(D[dade].dist!=D[1-dade].dist*2)
{
printf("0\n"); return 0;
}
}
printf("1\n");
printf("%d\n",a[D[dade].pos-1]+(a[D[dade].pos]-a[D[dade].pos-1])/2);
return 0;
}