Codeforces 714B. Filya and homework

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.