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;
}
posted @ 2018-10-01 16:14  EM-LGH  阅读(188)  评论(0编辑  收藏  举报