[CF714B] Filya and Homework
題目大意
給你 $n$ 個數字,問你存不存在某個正整數 $x$,使得能挑若干個數字 $+x$,然後挑若干個數字 $-x$,最後讓所有數字都相等?
題解
其實就是找出所有不同的數字,然後看看 (1) 是否種類數不超過 $2$ 種,或是 (2) 只有三種不同的數字、並且這三種數字形成等差數列?
參考程式碼
// by tmt514
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define SZ(x) ((int)(x).size())
#define FOR(it, c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef long long LL;
int main(void) {
int n, a[100005];
scanf("%d", &n);
for(int i=0;i<n;i++) scanf("%d", &a[i]);
sort(a, a+n);
n = unique(a, a+n) - a;
if(n<=2) { puts("YES"); }
else if (n==3 && a[1]-a[0] == a[2]-a[1]) puts("YES");
else puts("NO");
return 0;
}