CodeForces - 1015 D.Walking Between Houses

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 }

转自:传送门

原文地址:https://www.cnblogs.com/baiyi-destroyer/p/9434063.html

时间: 2024-10-04 23:40:32

CodeForces - 1015 D.Walking Between Houses的相关文章

CodeForces D. Walking Between Houses

http://codeforces.com/contest/1015/problem/D There are nn houses in a row. They are numbered from 11 to nn in order from left to right. Initially you are in the house 11. You have to perform kk moves to other house. In one move you go from your curre

Codeforces Round #501 (Div. 3) D Walking Between Houses

翻译 给你一条数轴(出题人很喜欢数轴啊),上面有排列着\(n\)个点,编号为\(1\)到\(n\)(你开始在\(1\)).每次你要从一个点移动到另一个点(可以重复).移动距离为两点坐标之差的绝对值,问你是否能否在\(k\)次机会内里一共移动\(s\)距离,并输出方案. 思路 第四题还是比较难的,赛后想了几分钟时才有头绪. 毫无疑问还是贪心(出题人很喜欢贪心啊)!那么我们分类讨论,先看不合法的情况 无论如何走你也走不到那个距离 无论如何走你也会走超那个距离 看来只要能走到那个距离除外都是不合法的,

Codeforces 327E Axis Walking (状压dp lowbit优化)

E. Axis Walking time limit per test:3 seconds memory limit per test:512 megabytes Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub lives at point 0 and Iahubina at point d. Iahub has n positive integ

Codeforces 1036B Diagonal Walking v.2 【贪心】

题目传送门:https://codeforces.com/contest/1036/problem/B 被这道题坑了,说白了还是菜. 贪心策略是先斜对角从(0,0)走到(n,n),然后往右拐(分奇偶考虑)[若n>m,swap(n,m)] 理论上是画画图,知道切入点是奇偶性后,就能想清楚了 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<q

Codeforces 327E Axis Walking 状压dp(水

题目链接:点击打开链接 题意: 给定n个数,随意排列. 给定k个违禁数b[]. 问:有多少个排列使得这个排列的 n项前缀和中不出现违禁数. (formally,if it's a legal permutation, sum[i] != b[j] (1<=i<=n, 1<=j<=k)) sum[0] = 0; sum[i] = sum[i-1]+a[permutaion[i]]; ==java党表示被tle,心疼自己T^T #include <stdio.h> cons

CodeForces 327E Axis Walking(状压DP+卡常技巧)

Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub lives at point 0 and Iahubina at point d. Iahub has n positive integers a1, a2, ..., an. The sum of those numbers is d. Suppose p1, p2, ..., pn is a p

CF D. Walking Between Houses (贪心)

题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过k次移动后,移动的总和可以刚好是s吗?若可以则输出YES并依次输出每次到达的房子的编号,否则输出NO. 分析:首先观察下NO的情况,如果s<k 也就是说总步数都比不是次数的话,那肯定是NO拉,或者s>k*(n-1) 无论如何走都到吧了总步数,那也是NO; 什么时候是YES呢?我们可以贪心下,尽可能

Codeforces Round #177 (Div. 2)---D. Polo the Penguin and Houses (组合数学+暴力)

Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer pi (1?≤?pi?≤?n). Little penguin Polo loves walking ar

Diagonal Walking v.2 CodeForces - 1036B (思维,贪心)

Diagonal Walking v.2 CodeForces - 1036B Mikhail walks on a Cartesian plane. He starts at the point (0,0)(0,0), and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point (0,0)(0,0), he can go to any o