zoukankan      html  css  js  c++  java
  • Codeforces 388A

    388A - Fox and Box Accumulation

    思路

    从小到大贪心模拟。

    代码

    #include<bits/stdc++.h>
    using namespace std;
    const int INF=0x3f3f3f3f; 
    const int N=105;
    int a[N]; 
    bool vis[N]={false};
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0); 
        int n;
        int ma=0;
        cin>>n;
        for(int i=0;i<n;i++) 
        {
            cin>>a[i];
        } 
        int ans=0,tot=n;
        sort(a,a+n);
        while(tot)
        {
            int cnt=0;
            for(int i=0;i<n;i++)
            {
                if(!vis[i]&&cnt<=a[i])
                {
                    vis[i]=true;
                    cnt++;
                    tot--;
                }
            }
            ans++;
        }
        cout<<ans<<endl;
        return 0; 
    } 
    #include<bits/stdc++.h>
    using namespace std;
    const int INF=0x3f3f3f3f; 
    const int N=105;
    int a[N]; 
    int Hash[N]={0};
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0); 
        int n;
        int ma=0;
        cin>>n;
        for(int i=0;i<n;i++) 
        {
            cin>>a[i];
            ma=max(ma,a[i]);
            Hash[a[i]]++;
        } 
        int ans=0;
        while(n)
        {
            int cnt=0;
            for(int i=0;i<=ma;i++)
            {
                while(Hash[i]&&i>=cnt)
                {
                    Hash[i]--;
                    cnt++;
                    n--;
                }
            }
            ans++;
        }
        cout<<ans<<endl;
        return 0; 
    } 
  • 相关阅读:
    052-141
    052-140
    052-139
    052-138
    需要做笔记的页面
    日期总是显示1900/01/01 0:00:00
    延迟加载的树控件
    (简单)关于summary的注释
    江南检测
    fineui动态添加用户控件
  • 原文地址:https://www.cnblogs.com/widsom/p/7228691.html
Copyright © 2011-2022 走看看