标签:not hellip may contain lang hid codeforce cond fine
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 mm 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 jj Natasha should select his food type bjbj and each day jj-th participant will eat one food package of type bjbj. 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 (1≤n≤1001≤n≤100, 1≤m≤1001≤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,…,ama1,a2,…,am (1≤ai≤1001≤ai≤100), 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
Input
3 9
42 42 42 42 42 42 42 42 42
Output
3
Hint
In the first example, Natasha can assign type 11 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 22 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个人活多少天。我们可以计算出 第i 天这些食物能活下来的最大人数,然后判断的时候,如果说哪一天活下来的最大人数大于n,输出对应的天数就可以了。(暴力天数)
1 #include <iostream> 2 #include <cstdio> 3 #include <stdlib.h> 4 #include <cmath> 5 #include <cstring> 6 #include <algorithm> 7 #include <string.h> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 #include <ctime> 14 #define maxn 320007 15 #define N 200005 16 #define INF 0x3f3f3f3f 17 #define PI acos(-1) 18 #define lowbit(x) (x&(-x)) 19 #define eps 0.000000001 20 #define read(x) scanf("%d",&x) 21 #define put(x) printf("%d\n",x) 22 #define memset(x,y) memset(x,y,sizeof(x)) 23 #define Debug(x) cout<<x<<" "<<endl 24 #define lson i << 1,l,m 25 #define rson i << 1 | 1,m + 1,r 26 using namespace std; 27 typedef long long ll; 28 bool cmp(int a,int b) 29 { 30 return a>b; 31 } 32 int main() 33 { 34 int a[200]; 35 int n,m; 36 while(cin>>n>>m) 37 { 38 int ans=0; 39 memset(a,0); 40 for(int i=1; i<=m; i++) 41 { 42 int t; 43 cin>>t; 44 if(a[t]==0) 45 { 46 ans++; 47 } 48 a[t]++; 49 } 50 sort(a+1,a+101,cmp); 51 int b[210]; 52 int maxx=-1; 53 int num=0; 54 int flag=0; 55 memset(b,0); 56 for(int i=1; i<=200; i++) 57 { 58 int index=0; 59 for(int j=1; j<=ans; j++) 60 { 61 if(a[j]/i) 62 { 63 int t=a[j]/i; 64 index+=t; 65 } 66 } 67 b[i]=index; 68 } 69 for(int i=1; i<=200; i++) 70 { 71 if(b[i]>=n) 72 flag=i; 73 } 74 cout<<flag<<endl; 75 } 76 return 0; 77 }
转自:传送门
CodeForces - 1015 D.Walking Between Houses
标签:not hellip may contain lang hid codeforce cond fine
原文地址:https://www.cnblogs.com/baiyi-destroyer/p/9434063.html