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,输出对应的天数就可以了。(暴力天数)
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 320007
#define N 200005
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
using namespace std;
typedef long long ll;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int a[];
int n,m;
while(cin>>n>>m)
{
int ans=;
memset(a,);
for(int i=; i<=m; i++)
{
int t;
cin>>t;
if(a[t]==)
{
ans++;
}
a[t]++;
}
sort(a+,a+,cmp);
int b[];
int maxx=-;
int num=;
int flag=;
memset(b,);
for(int i=; i<=; i++)
{
int index=;
for(int j=; j<=ans; j++)
{
if(a[j]/i)
{
int t=a[j]/i;
index+=t;
}
}
b[i]=index;
}
for(int i=; i<=; i++)
{
if(b[i]>=n)
flag=i;
}
cout<<flag<<endl;
}
return ;
}
转自:传送门
CodeForces - 1015 D.Walking Between Houses的更多相关文章
- Codeforces Round #501 (Div. 3) 1015D Walking Between Houses
D. Walking Between Houses time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Walking Between Houses(贪心+思维)
Walking Between Houses There are nn houses in a row. They are numbered from 11 to nn in order from l ...
- Codeforces Round #501 (Div. 3) D. Walking Between Houses
题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n ...
- Codeforces Round #501 (Div. 3) D. Walking Between Houses (思维,构造)
题意:一共有\(n\)个房子,你需要访问\(k\)次,每次访问的距离是\(|x-y|\),每次都不能停留,问是否能使访问的总距离为\(s\),若能,输出\(YES\)和每次访问的房屋,反正输出\(NO ...
- Codeforces 327E Axis Walking 状压dp
这题真的有2500分吗... 难以置信... #include<bits/stdc++.h> #define LL long long #define fi first #define s ...
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- 【CF1015D】Walking Between Houses(构造,贪心)
题意:从1开始走,最多走到n,走k步,总长度为n,不能停留在原地,不能走出1-n,问是否有一组方案,若有则输出 n<=1e9,k<=2e5,s<=1e18 思路:无解的情况分为两种: ...
- CF D. Walking Between Houses (贪心)
题意: 现在有n个房子排成一列,编号为1~n,起初你在第1个房子里,现在你要进行k次移动,每次移动一都可以从一个房子i移动到另外一个其他的房子j里(i != j),移动的距离为|j - i|.问你进过 ...
- codeforces 1036B - Diagonal Walking v.2【思维+构造】
题目:戳这里 题意:起点(0,0),终点(n,m),走k步,可以走8个方向,问能不能走到,能走到的话最多能走多少个斜步. 解题思路:起点是固定的,我们主要分析终点.题目要求走最多的斜步,斜步很明显有一 ...
随机推荐
- 家庭记账本之微信小程序(八)
寒假总结 寒假充满着腥风血雨,不过在努力下还是完成了寒假的任务,虽说没有出去找活干,毕竟在寒假这段时间不怎么好找,但是我在自己家的店里帮这父母工作了一段时间,也算是颇有收获,在短暂的学习后也算勉强完成 ...
- MFC 的资源文件 就是那个后缀名是 .rc的那个
参考: http://blog.csdn.net/zgrjkflmkyc/article/details/16897881 http://www.oschina.net/question/565065 ...
- centos7.5图形界面与命令行界面转换
查看当前状态下的显示模式: # systemctl get-default 转换为图形界面: # systemctl set-default graphical.target 转换为命令行界面: # ...
- Kaggle初学者五步入门指南,七大诀窍助你享受竞赛
Kaggle 是一个流行的数据科学竞赛平台,已被谷歌收购,参阅<业界 | 谷歌云官方正式宣布收购数据科学社区 Kaggle>.作为一个竞赛平台,Kaggle 对于初学者来说可能有些难度.毕 ...
- vue mand-mobile ui Stepper步进器默认值传字符串进去不起作用
vue mand-mobile ui Stepper步进器默认值传字符串进去不起作用 Stepper 步进器 的默认值有没有弄过的,看了组件只能默认数字的,传字符串进去不起作用<div slot ...
- Python Redis hash
hash表现形式上有些像pyhton中的dict,可以存储一组关联性较强的数据 , redis中Hash在内存中的存储格式如下图: hset(name, key, value) # name对应的ha ...
- Android组件系列----Intent详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- 内置函数filter()和匿名函数lambda解析
一.内置函数filter filter()函数是 Python 内置的一个高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断,返回由符合条件迭代器 ...
- svn版本备份和恢复注意事项
转帖的,因为我经常要用到,所以也在我的博客上记录一下: 注意:备份不备份日志,你想备份日志就要单独在客户端备了,具体步骤百度上都有 svn备份常用命令1.完全备份和增量备份svn.svnadmin ...
- CSS【05】:CSS三大特性
继承性 作用:给父元素设置一些属性,子元素也可以使用,这个我们就称之为继承性 示例代码: <style> div { color: red; } </style> <di ...