• AtCoder Grand Contest 016 B


    B - Colorful Hats


    Time limit : 2sec / Memory limit : 256MB

    Score : 700 points

    Problem Statement

    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≤aiN−1

    Input

    Input is given from Standard Input in the following format:

    N
    a1 a2  aN
    

    Output

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


    Sample Input 1

    Copy
    3
    1 2 2
    

    Sample Output 1

    Copy
    Yes
    

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


    Sample Input 2

    Copy
    3
    1 1 2
    

    Sample Output 2

    Copy
    No
    

    From the remark of cat 1, we can see that cat 2 and 3 wear hats of the same color. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats of the same color. Therefore, cat 1 and 2 wear hats of the same color, which contradicts the remark of cat 3.


    Sample Input 3

    Copy
    5
    4 3 4 3 4
    

    Sample Output 3

    Copy
    No
    

    Sample Input 4

    Copy
    3
    2 2 2
    

    Sample Output 4

    Copy
    Yes
    

    Sample Input 5

    Copy
    4
    2 2 2 2
    

    Sample Output 5

    Copy
    Yes
    

    Sample Input 6

    Copy
    5
    3 3 3 3 3
    

    Sample Output 6

    Copy
    No

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<iostream>
    #include<queue>
    #include<map>
    #include<cmath>
    #include<set>
    #include<stack>
    #define ll long long
    #define pb push_back
    #define max(x,y) ((x)>(y)?(x):(y))
    #define min(x,y) ((x)>(y)?(y):(x))
    #define cls(name,x) memset(name,x,sizeof(name))
    using namespace std;
    const int inf=1e9+10;
    const int maxn=1e6+10;
    const int maxm=20;
    const int mod=1e9+7;
    const double pi=acos(-1.0);
    int n;
    int num[maxn];
    int main()
    {
        //freopen("in.txt","r",stdin);
        while(~scanf("%d",&n))
        {
            int minnum=inf,maxnum=0;
            for(int i=0;i<n;i++)
            {
                scanf("%d",&num[i]);
                minnum=min(minnum,num[i]);
                maxnum=max(maxnum,num[i]);
            }
            if(!(minnum+1==maxnum||minnum==maxnum))
            {
                printf("No
    ");
                continue;
            }
            int color=maxnum;
            int maxc=0;
            for(int i=0;i<n;i++)
            {
                if(maxnum-1==num[i]) color--;
                else maxc++;
            }
            if(minnum+1==maxnum)
            {
                if(maxc>=color*2&&color>=1)
                    printf("Yes
    ");
                else printf("No
    ");
            }
            else
            {
                if(maxc>=color*2||maxc==color+1)
                    printf("Yes
    ");
                else printf("No
    ");
            }
        }
        return 0;
    }


  • 相关阅读:
    初学 python 之 多级菜单实现原理
    初学 python 之 用户登录实现过程
    Sqlmap使用教程
    对伪静态网站实施注射
    干货!IT小伙伴们实用的网站及工具大集合!持续更新!
    lnmp、lamp、lnmpa一键安装包(Updated: 2016-4-12)
    如何入门 Python 爬虫?
    在Windows Live Writer中插入C# code
    IIS装好后,局域网不能访问
    修改win7登录界面
  • 原文地址:https://www.cnblogs.com/mgz-/p/7081409.html
Copyright © 2020-2023  润新知