Planning The Expedition(暴力枚举+map迭代器)

Description

Natasha is planning an expedition to Mars for nn 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 aiai.

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 bjbj and each day j-th participant will eat one food package of type bj. The values bjbj 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 nn and mm (1n100 1m100) — 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 (1ai100), where aiai is the type of ii-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.

Sample Input

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

Hint

In the first example, Natasha can assign type 1 food to the first participant, the same type 11 to the second, type 55 to the third and type 22 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 44 packages of type 11, two packages of type 22 and two packages of type 55).

In the second example, there are 100100 participants and only 11 food package. In this case, the expedition can't last even 11 day.

题目意思:有n个人要去参加火星探险活动,准备了m份的食物,编号相同的属于一种食物,每个人每天都要吃一份食物并且必须一直吃一种食物,要是有人没有食物了就返回。问最后所有人一共可以存活多少天。

解题思路:使用map记录各种食物的个数,对能够存活的天数进行枚举暴力,使用迭代器对食物种类进行枚举,判断所有的食物能够支持的人数。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<map>
 4 #include<algorithm>
 5 using namespace std;
 6 map<int,int>mp;
 7 int main()
 8 {
 9     int n,m,i,j,ans,x,p,sum;
10     scanf("%d%d",&n,&m);
11     for(i=1; i<=m; i++)
12     {
13         scanf("%d",&x);
14         mp[x]++;
15     }
16     if(m<n)
17     {
18         printf("0\n");
19         return 0;
20     }
21     p=m/n;///能活下来的最大天数
22     map<int,int>::iterator it;
23     for(i=p; i>0; i--) ///对存活的天数进行暴力
24     {
25         sum=0;
26         for(it=mp.begin(); it!=mp.end(); it++)///对口粮种类进行暴力
27         {
28             sum+=it->second/i;
29         }
30         if(sum>=n)///判断最多能支持多少人
31         {
32             break;
33         }
34     }
35     printf("%d\n",i);
36     return 0;
37 }

 

posted @ 2018-08-06 09:56  王陸  阅读(547)  评论(0编辑  收藏  举报