Codeforces_714_B

http://codeforces.com/problemset/problem/714/B

 

当不同大小整数有1、2个时,肯定成立,3个时,需要判断,大于等于4个,则肯定不成立。

 

#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;


long long a [5];
int main()
{
    int n;
    cin >> n;
    int num = 0;
    while(n--)
    {
        if(num > 3)
        {
            break;
        }
        long long temp;
        cin >> temp;
        int flag = 1;
        for(int i = 0;i < num;i++)
        {
            if(a[i] == temp)    flag = 0;
        }
        if(flag) a[num++] = temp;
    }
    if(num == 1 || num == 2)    printf("YES\n");
    else if(num == 3)
    {
        sort(a,a+3);
        if(a[0]+a[2] == 2*a[1]) printf("YES\n");
        else    printf("NO\n");
    }
    else
    {
        printf("NO\n");
    }

    return 0;
}

 

posted @ 2016-09-14 12:45  zzzzzzzzhu  阅读(207)  评论(0编辑  收藏  举报