B. Planning The Expedition

题目链接

Codeforces Round #499 (Div. 2)--B. Planning The Expedition

题解

简单题。题意大概是有m种食物,每种食物有若干份,n个人取食物且每个人只能取一种食物,求n个人中拿最少的人拿多少份。

注意到数据规模只有可怜的100,从100到0枚举一遍即可。

代码

#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int n, m;
int a[105], b[105];

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    for (int i = 100; i >= 1; i--) {
        int temp = 0;
        for (int j = 1; j <= 100; j++) {
            temp += b[j] / i;
        }
        if (temp >= n) {
            cout << i;
            return 0;
        }
    }
    cout << 0;    
}

标签: implementation, binary search, brute force

添加新评论