# CodeForces - 382C Arithmetic Progression 思维

Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers a1, a2, ..., an of length n, that the following condition fulfills:
a2 - a1 = a3 - a2 = a4 - a3 = ... = ai + 1 - ai = ... = an - an - 1.
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has n cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting n + 1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input
The first line contains integer n (1 ≤ n ≤ 105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Example
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
typedef long long ll;
int a[maxn],d[maxn];
int main()
{
set<int>st;
int n;
cin>>n;
st.clear();
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+1+n);
if(n==1)
{
printf("-1\n");
return 0;
}
if(n==2)
{
d[0]=a[2]-a[1];
st.insert(a[2]+d[0]);
st.insert(a[1]-d[0]);
if(d[0]%2==0)
st.insert(a[1]+d[0]/2);
}
else if(n==3)
{
d[0]=a[2]-a[1];
d[1]=a[3]-a[2];
if(d[0]==d[1])
{
st.insert(a[1]-d[0]);
st.insert(a[3]+d[0]);
}
if(d[0]==2*d[1])
{
st.insert(a[1]+d[1]);
}
if(d[1]==2*d[0])
{
st.insert(a[2]+d[0]);
}
}
else
{
int k=0,count=0;
map<int ,int >mp;
for(int i=2;i<=n;i++)
{
k=a[i]-a[i-1];
mp[k]++;
if(mp[k]==1)
{
d[count++]=k;
if(count>=3)
break;
}
}
if(count==1)
{
st.insert(a[1]-d[0]);
st.insert(a[n]+d[0]);
}
else if(count==2)
{
if(mp[d[0]]==1&&d[0]==2*d[1])
{
for(int i=2;i<=n;i++)
{
if(a[i]-a[i-1]==d[0])
{
st.insert(a[i]-d[1]);
break;
}
}

}
if(mp[d[1]]==1&&d[1]==2*d[0])
{
for(int i=2;i<=n;i++)
{
if(a[i]-a[i-1]==d[1])
{
st.insert(a[i]-d[0]);
break;
}
}
}
}

}
bool flag=false;
printf("%d\n",st.size());
set<int>::iterator it;
for(it=st.begin();it!=st.end();it++)
{
if(flag)
printf(" ");
printf("%d",*it);
flag=true;
}
if(st.size())
printf("\n");
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120