zoukankan      html  css  js  c++  java
  • B. Filya and Homework

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

    给定一个序列,对于每一个元素,只能 + 或者 - 一个数val。这个数一旦选定,就不能改。

    问能否变成全部数字都一样。

    一开始还以为没 + 一次,就要 - 一次。 结果不是,一直wa

    那么这样的话,这题的正解是观察法。也可以证明。

    ①、全部数字都一样、有两个不同数字、三个不同数字(a[1] + a[3] =  2 * a[2])这些都易懂

    那4个不同数字为什么是no呢

    可以想象成找不到一个点,作为圆心,包含另外3个点(这3点在一直线)。

    所以对于有三个不同数字那个,其实就是判断是否为圆心。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    const int maxn = 100000 + 20;
    int a[maxn];
    int n;
    LL val;
    set<int> ss;
    void work() {
        cin >> n;
        LL sum = 0;
        for (int i = 1; i <= n; ++i) {
            scanf("%d", &a[i]);
            sum += a[i];
            ss.insert(a[i]);
        }
    //    sort(a + 1, a + 1 + n);
        if (ss.size() == 1 || ss.size() == 2) {
            printf("YES
    ");
            return ;
        } else if (ss.size() >= 4) {
            printf("NO
    ");
            return ;
        } else {
            int now = 0;
            for (set<int> :: iterator it = ss.begin(); it != ss.end(); ++it) {
                a[++now] = *it;
            }
            if (a[1] + a[3] == 2 * a[2]) {
                printf("YES
    ");
                return ;
            }
            printf("NO
    ");
        }
    }
    
    int main() {
    #ifdef local
        freopen("data.txt","r",stdin);
    #endif
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    网站色彩搭配
    web前端小知识,安书整理的
    java基础
    简单android UI必会
    java学习总结
    java字符常量与字符串常量的区别
    最近的学习
    简单的ps操作
    HTTP协议概述
    ABP 学习 Setting
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/5870674.html
Copyright © 2011-2022 走看看