枚举,找限制条件

本博客探讨了一个关于为火星探险队规划食物供应的问题。任务是为n个人分配每日食物包,每个包有不同的类型。每个人都必须每天吃相同类型的食物,且整个探险期间必须保持一致。挑战在于确定最长的探险天数,使得每个人都能得到足够数量的食物。通过枚举不同的天数并找到满足条件的最大值,即每天所有类型的食品包供给总和不少于n,来解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
a
i
.

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
b
j
and each day
j
-th participant will eat one food package of type
b
j
. The values
b
j
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
a
1
,
a
2
,

,
a
m
(
1

a
i

100
), where
a
i
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
inputCopy
4 10
1 5 2 1 1 1 2 5 7 2
outputCopy
2
inputCopy
100 1
1
outputCopy
0
inputCopy
2 5
5 4 3 2 1
outputCopy
1
inputCopy
3 9
42 42 42 42 42 42 42 42 42
outputCopy
3
Note
In the first example, Natasha can assign type
1
food to the first participant, the same type
1
to the second, type
5
to the third and type
2
to the fourth. In this case, the expedition can last for
2
days, since each participant can get two food packages of his food type (there will be used
4
packages of type
1
, two packages of type
2
and two packages of type
5
).

In the second example, there are
100
participants and only
1
food package. In this case, the expedition can’t last even
1
day.
THINK:
题意是说有原料给人供应,每个人第一天拿到的是什么样子的,以后每天都是相同的,问这些原料可以供应多少天,只要有一个人没有了都不行;
思路:枚举天数,找限制条件,在这个限制条件下看可以供应多少天;限制条件就是当供应的人数小于题目给的人数了就说明这一天供应不下去了,就只能输出前一天
自己的错误思路:想了好几种方法,但是都是找规律去看题,就与题意不挂边了,以后要看这个题的条件是什么,不要纠结在数据上,这个题考什么,考可以维持多少天,限制条件是什么,限制条件是人数得是题目要求的人数,怎么实现这个限制条件;每种原料的个数模相应的天数就是要每种原料要供养的人数,加起来看看;

#include<stdio.h>
#include<stdlib.h>
int a[101];
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++)
    {
        int t;
        scanf("%d",&t);
        a[t]++;
    }
    int i;
    for(i=1;i<=100;i++)
    {
        int sum=0;
        for(int j=1;j<=100;j++)
        {
            sum+=a[j]/i;
        }
        if(sum<m)break;
    }
    printf("%d\n",i-1);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值