题目链接:http://codeforces.com/problemset/problem/714/B
题意:给一个正整数序列,问是否有一个x,使得一些数加上x,一些数减去x,然后整个序列所有的数相等。
排序判断就行了。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;
int a[100100];
int main() {
int n;
scanf("%d", &n);
int i;
for(i = 0; i < n; i++) {
scanf("%d", a + i);
}
sort(a, a + n);
int type = unique(a, a + n) - a;
if(type < 3 || type == 3 && a[1] - a[0] == a[2] - a[1]) puts("YES");
else puts("NO");
return 0;
}