Codefoces1011B

Codeforce Round #499/B Coderforces1011B

原题:

B. Planning The Expedition
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Natasha is planning an expedition to Mars for n people. One of the important tasks is to provide food for each participant.

The warehouse has m daily food packages. Each package has some food type ai.

Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.

Formally, for each participant j Natasha should select his food type bj and each day j-th participant will eat one food package of type bj. The values bj for different participants may be different.

What is the maximum possible number of days the expedition can last, following the requirements above?

Input
The first line contains two integers n and m (1≤n≤100, 1≤m≤100) — the number of the expedition participants and the number of the daily food packages available.

The second line contains sequence of integers a1,a2,…,am (1≤ai≤100), where ai is the type of i-th food package.

Output
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.

Examples
input
4 10
1 5 2 1 1 1 2 5 7 2
output
2
input
100 1
1
output
0
input
2 5
5 4 3 2 1
output
1
input
3 9
42 42 42 42 42 42 42 42 42
output
3

题意:

总共有n个人,m包食物,食物的种类不同,每个人每天吃的食物必须是同种食物,不同的人也可以吃同种食物。给出m包食物的种类编号,问n个人最多能吃多少天?

解题思路:

  • 首先预处理m个数据,将数据存在数组a[]中,累加每种编号食物的数量。
  • 判断天数是否为0。
    总共有m包食物,n个人,所以最大天数是max=m/n,当n小于m时,也就是max=0,天数是0,否则至少有1天。
  • 暴力从max到1,递减check该天数是否合理。
    check的方法是遍历a[]数组,用每个元素除以天数,累加为sum,表示可供sum人吃i天,如果sum大于等于n,则最大天数为i

代码:

#include <iostream>
using namespace std;
int n,m;
int aa[107];
int main()
{
    cin>>n>>m;
    int num;
    for(int i=0;i<m;i++)
    {
        cin>>num;
        aa[num]++;
    }
    int Max=m/n;
    if(Max==0)
    {
        cout<<0<<endl;
        return 0;
    }
    int sum;
    for(int i=Max;i>0;i--)
    {
        sum=0;
        for(int j=1;j<=100;j++)
            sum+=aa[j]/i;
        if(sum>=n)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值