zoukankan      html  css  js  c++  java
  • Codeforces div2 #499 B. Planning The Expedition 大水题

    已经是水到一定程度了QAQ…
    Code:

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    const int maxn = 105;
    int tp[maxn], idx[maxn], n,m, spare[maxn], cnt;
    bool cmp(int i,int j) { return i > j;}
    inline bool check(int val)
    {
        int fin = 0;
        for(int i = 1;i <= n; ++i)
        {
            while(spare[i] >= val) 
            {
                ++fin, spare[i] -= val;
                if(fin >= n) break;
            }
        }
        if(fin >= n) return 1; 
        return 0;
    }
    int main()
    {
        //freopen("input.in","r",stdin);
        scanf("%d%d",&n,&m);
        for(int i = 1;i <= m; ++i)
        {
            int u; scanf("%d",&u); 
            if(!idx[u]) idx[u] = ++cnt;
            ++tp[idx[u]];
        }
        sort(tp + 1, tp + 1 + cnt, cmp);
        int l = 1, r = 10000000, ans = 0;
        while(l <= r)
        {
            int mid = (l + r) >> 1;
            for(int i = 1;i <= cnt; ++i) spare[i] = tp[i];
            if(check(mid)) l = mid + 1, ans = mid;
            else r = mid - 1;
        }
        printf("%d",ans);
        return 0;
    }
    
  • 相关阅读:
    poj 2104 C
    2015 百度之星初赛 1 2 2015ACM/ICPC亚洲区上海站 codeforces 851
    3.10补
    3.9补
    3.8补
    3.6补
    3.5补
    3.4补
    3.3补
    2.35补
  • 原文地址:https://www.cnblogs.com/guangheli/p/9845132.html
Copyright © 2011-2022 走看看