活生生打成了大模拟。。。
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int>PII; const double eps=1e-5; const double pi=acos(-1.0); //const int mod=1e9+7; const int INF=0x3f3f3f3f; //http://codeforces.com/contest/382/submission/22599025 const int N=1e5+10; int a[N]; int ans[N],num; int n; void shuchu() { sort(ans,ans+num); int e=unique(ans,ans+num)-ans; printf("%d ",e); for(int i=0; i<e; i++) printf("%d ",ans[i]); } map<int,int>mp; int mp_num; int main() { scanf("%d",&n); for(int i=1; i<=n; i++) scanf("%d",&a[i]); sort(a+1,a+1+n); if(n==1) { puts("-1"); return 0; } if(n==2) { int d=a[n]-a[n-1]; if(d%2==1) { num=0; ans[num++]=a[n-1]-d; ans[num++]=a[n]+d; shuchu(); } else { num=0; ans[num++]=a[n-1]-d; ans[num++]=a[n]-d/2; ans[num++]=a[n]+d; shuchu(); } return 0; } //3 4 4 5 //1 2 3 //1 2 4 int d1,temp,d2,num1,num2; int dx1,dx2; num2=num1=0; d1=a[2]-a[1]; dx1=2; num1++; mp_num=1; mp[d1]=1; for(int i=3; i<=n; i++) { temp=a[i]-a[i-1]; if(!mp[temp]) { mp[temp]=1; mp_num++; } if(temp!=d1) { num2++; dx2=i; d2=temp; } else num1++; } if(mp_num>=3) { puts("0"); return 0; } if(!num2) { num=0; ans[num++]=a[1]-d1; ans[num++]=a[n]+d1; shuchu(); } else { if(num1==1&&num2==1) { int res=a[dx2]-d1; if(res*2==(a[dx2]+a[dx2-1])) { puts("1"); printf("%d ",res); return 0; } res=a[dx1]-d2; if(res*2==(a[dx1]+a[dx1-1])) { puts("1"); printf("%d ",a[dx1]-d2); return 0; } puts("0"); } else if(num2==1) { int res=a[dx2]-d1; if(res*2==(a[dx2]+a[dx2-1])) { puts("1"); printf("%d ",res); } else puts("0"); } else if(num1==1) { int res=a[dx1]-d2; if(res*2==(a[dx1]+a[dx1-1])) { puts("1"); printf("%d ",a[dx1]-d2); } else puts("0"); } else puts("0"); } return 0; }