zoukankan      html  css  js  c++  java
  • AtCoder Grand Contest 016 B

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 72  解决: 18
    [提交] [状态] [命题人:admin]

    题目描述

    There are N cats. We number them from 1 through N.

    Each of the cats wears a hat. Cat i says: "there are exactly ai different colors among the N−1 hats worn by the cats except me."

    Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.

    Constraints
    2≤N≤105
    1≤ai≤N−1

    输入

    Input is given from Standard Input in the following format:

    N
    a1 a2 … aN

    输出

    Print Yes if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print No otherwise.

    样例输入

    3
    1 2 2
    

    样例输出

    Yes
    

    提示

    For example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it is consistent with the remarks of the cats.

    来源/分类

     
    可以证明,ai的最大值与最小值至多相差1,设共有col种颜色
    1.ai自己一个颜色,则ai = col-1
    2.有其他猫和ai同一个颜色,则ai = col
     
    取ai的最大值max,最小值min。
    1.当max = col-1时,此时所有的ai相等,均为col-1,cnt[max] = n,max = n-1。
    2.当max = col时,cnt[max]+cnt[min] = n因为min = col-1,所以这m个猫颜色各不相同。而剩下的猫中,每种颜色都至少有两只,则这些猫的颜色col2,1<=col2<=(n-cnt[min])/2,所以cnt[min]<col<=cnt[min]+(n-cnt[min])/2.
     
     
     
    #include "bits/stdc++.h"
    
    using namespace std;
    const int maxn = 1e5 + 100;
    
    int cnt[maxn];
    
    int main() {
        //freopen("input.txt", "r", stdin);
        int n;
        cin >> n;
        int x, m = -1;
        for (int i = 0; i < n; i++) {
            cin >> x;
            cnt[x]++;
            m = max(m, x);
        }
        if ((cnt[m] == n && m == n - 1) ||
            (cnt[m] + cnt[m - 1] == n && cnt[m - 1] <m &&
             (m - cnt[m - 1]) * 2 <= cnt[m]))
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
        return 0;
    }
  • 相关阅读:
    gcc 不同平台不同宏写法 Function Multiversioning
    linux win10 挂载 C盘 系统盘 ntfs 问题 休眠 快速启动关闭了
    archlinux wine
    ssm批量操作易错点
    行政区划代码
    ssm获取session
    layui 批量删除点击不起作用
    layui分页失效问题
    java 获取服务器配置信息【使用sigar、sql语句、ServerInfo】
    ssm中html跳转之后乱码
  • 原文地址:https://www.cnblogs.com/albert-biu/p/10517961.html
Copyright © 2011-2022 走看看