zoukankan      html  css  js  c++  java
  • CodeForces 128D Numbers 构造

    D. Numbers
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    One day Anna got the following task at school: to arrange several numbers in a circle so that any two neighboring numbers differs exactly by 1. Anna was given several numbers and arranged them in a circle to fulfill the task. Then she wanted to check if she had arranged the numbers correctly, but at this point her younger sister Maria came and shuffled all numbers. Anna got sick with anger but what's done is done and the results of her work had been destroyed. But please tell Anna: could she have hypothetically completed the task using all those given numbers?

    Input

    The first line contains an integer n — how many numbers Anna had (3 ≤ n ≤ 105). The next line contains those numbers, separated by a space. All numbers are integers and belong to the range from 1 to 109.

    Output

    Print the single line "YES" (without the quotes), if Anna could have completed the task correctly using all those numbers (using all of them is necessary). If Anna couldn't have fulfilled the task, no matter how hard she would try, print "NO" (without the quotes).

    Sample test(s)
    Input
    4
    1 2 3 2
    Output
    YES
    Input
    6
    1 1 2 2 2 3
    Output
    YES
    Input
    6
    2 4 1 1 2 2
    Output
    NO
    题面意思:
    大概就是讲有n张牌,这N张牌需要围成一个圈,要求牌和他相邻的牌最多相差1
    问可不可行

    思路:大概就是缩吧,比如 121可以看成1,12121也可以看成1。
    在草稿本上画画就可以知道,最后状态是类似于12这种环
    当然,出现断链的时候,当然是不可行的啦
    于是就乱搞吧= =
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define maxn 100001
    const int inf=0x7fffffff;   //无限大
    int a[maxn];
    int t[maxn];
    int main()
    {
        int n;
        while(cin>>n){
        cin>>a[0];
        int mi=a[0];
        for(int i=1;i<n;i++)
        {
            cin>>a[i];
            mi=min(a[i],mi);
        }
        sort(a,a+n);
        int flag=1;
    
        for(int i=0;i<n;i++)
        {
            if(a[i]-mi>=maxn)
            {
                flag=0;
                break;
            }
            t[a[i]-mi]++;
        }
    
        if(flag==1)
        for(int i=1;i<a[n-1]-mi+1;i++)
        {
            //cout<<t[i]<<endl;
            if(t[i]==0)
            {
                flag=0;
                break;
            }
            if(i!=a[n-1]-mi&&t[i]<=t[i-1])
            {
                flag=0;
                break;
            }
            if(i==a[n-1]-mi&&t[i]!=t[i-1])
            {
                flag=0;
                break;
            }
            t[i]-=t[i-1];
        }
        if(flag==0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
        }
        return 0;
    }
     


  • 相关阅读:
    css 设置特定条件下的标签
    vue实现导航菜单滚动
    input 默认样式样式 样式修改
    vue 倒计时
    微信小程序 botton默认样式删除
    Notepad++ 快捷键
    css实现div水平垂直居中
    Python爬虫爬取1905电影网视频电影并存储到mysql数据库
    Python爬虫爬取搜狐视频电影并存储到mysql数据库
    第一阶段(十)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4230857.html
Copyright © 2011-2022 走看看