zoukankan      html  css  js  c++  java
  • Codeforces Round #371 (Div. 2)

    题目链接:http://codeforces.com/contest/714/problem/B

    题意:给定一个长度为N的初始序列,然后问是否能找到一个值x,然后使得序列的每个元素+x/-x/不变,最后把序列变成各个元素都相等(序列每个元素只能进行操作一次)

    思路:因为每个元素只能操作一次,而且操作的值只有一个值x。那么就可以发现当序列中存在3个以上的互不相等的数时一定不能构造要求的序列。 当序列存在3个一下的互补相同的数时,一定能构造要求的序列。现在要考虑的是刚刚有3个互不相同的序列时,把序列去重+排序后,如果数2-数1=数3-数2.则可以构造,否则不能构造。

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<string>
    #include<queue>
    #include<vector>
    #include<time.h>
    #include<cmath>
    #include<set>
    using namespace std;
    typedef long long int LL;
    const int MAX = 2000 + 5;
    int main(){
    //#ifdef kirito
    //    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
    //#endif
        int n,num;
        while (~scanf("%d", &n)){
            set<int>se;
            for (int i = 0; i < n; i++){
                scanf("%d", &num); se.insert(num);
            }
            if (se.size()>3){
                printf("NO
    ");
            }
            else if (se.size() == 3){
                vector<int>m;
                for (set<int>::iterator it = se.begin(); it != se.end(); it++){
                    m.push_back(*it);
                }
                sort(m.begin(), m.end());
                if (m[1] - m[0] == m[2] - m[1]){
                    printf("YES
    ");
                }
                else{
                    printf("NO
    ");
                }
            }
            else{
                printf("YES
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    Nginx 高级配置
    nginx安装和优化配置
    location语法介绍
    iptables
    通过 loganalyzer 展示数据库中的系统日志
    ubuntu_server16.04详细安装步骤
    内存控制mmap的原型和使用方法
    C语言中open函数read函数lseek函数是如何使用的
    gdb调试工具的基本使用
    C语言如何制作静态库
  • 原文地址:https://www.cnblogs.com/kirito520/p/5872819.html
Copyright © 2011-2022 走看看