Title Link: Http://codeforces.com/problemset/problem/714/B
Test instructions
Give you an array of n numbers, and ask if you have an X so that some number in this array is x, and some number minus x is equal to all numbers.
Ideas:
If the number of unequal numbers in this array is greater than 3, then x cannot exist. Otherwise, if the array has only three numbers and is set to A, B, C (a < b < c), then b-a = = C-b must also be met. So that all the numbers equal to A and b-a to B, all the numbers equal to C minus the C-b also becomes B, then You can make all the numbers equal. If the array has only two numbers that are different and set to a, B, then all the numbers in this array will be equal (B-A) or the number of all values B minus (b-a). If the number in this array is all equal, then there is no change, so the above three cases satisfy the test instructions.
Code:
1#include <bits/stdc++.h>2 3 using namespacestd;4typedefLong LongLL;5 Const intMAXN =100000;6 intARV[MAXN +3];7 8 intMain () {9Ios_base::sync_with_stdio (0); Cin.tie (0);Ten intN CIN >>N; One for(inti =0; I < n; i++) Cin >>Arv[i]; ASort (ARV, ARV +n); - intJUD[MAXN +3], Len =0; -jud[len++] = arv[0]; the for(inti =1; I < n; i++)if(Arv[i]! = arv[i-1]) jud[len++] =Arv[i]; - if(len = =1|| Len = =2|| (len = =3&& jud[2] + jud[0] = = jud[1] *2)) cout <<"YES"<<Endl; - Elsecout <<"NO"<<Endl; - return 0; +}
Codeforces 714B. Filya and homework