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个方向,问能不能走到,能走到的话最多能走多少个斜步. 解题思路:起点是固定的,我们主要分析终点.题目要求走最多的斜步,斜步很明显有一 ...
随机推荐
- AppFabric查询工作流实例
安装 通过IIS查询工作流实例,可以操作挂起,首先打开WF+WCF的站点: 这里可以搜索工作流实例:例如根据工作流ID.创建日期.状态等查询 下方的搜索结果可以查看结果 资源 Windows Serv ...
- reactjs中使用高德地图计算两个经纬度之间的距离
第一步下载依赖 npm install --save react-amap 第二步,在组件中使用 import React, { Component } from 'react' import { L ...
- Unicode编码学习
unicode基础知识 简单来说,** unicode 是字符集,utf-8,utf-16,utf-32是编码规则.** unicode 字符集: ttps://unicode-table.com/ ...
- skywalking学习之路---skywalking环境从零搭建部署
介绍 SkyWalking项目是由华为大牛吴晟开源的个人项目,目前已经加入Apache孵化器.SkyWalking项目的核心目标是针对微服务.Cloud Native.容器化架构提供应用性能监控和分布 ...
- GO语言常量和变量
标识符与关键字 标识符 人为定义有特殊意义的词,Go语言中标识符由字母数字和_(下划线)组成,并且只能以字母和_开头. 关键字 关键字是指编程语言中预先定义好的具有特殊含义的标识符. GO语言中有25 ...
- redis重要知识点
redis是一种高级的key:value存储系统,其中value支持五种数据类型: 1.字符串(strings) 2.字符串列表(lists) 3.字符串集合(sets) 4.有序字符串集合(sort ...
- 通过gmapping和伪造的odom,完成Kinect建图
传感器信息: 环境深度信息:sensor_msgs/laserScan -----> RGBD三维点云数据:通过ros功能包depthimage to laserscan完成深度相机数据转换成激 ...
- Python Redis 发布订阅
发布者:服务器 订阅者:Dashboad和数据处理 频道主逻辑 import redis class RedisHelper: def __init__(self): # 链接服务端 self.__c ...
- ELK(ElasticSearch+Logstash+ Kibana)搭建实时日志分析平台
一.简介 ELK 由三部分组成elasticsearch.logstash.kibana,elasticsearch是一个近似实时的搜索平台,它让你以前所未有的速度处理大数据成为可能. Elastic ...
- SIP 编解码器
编解码器,编码器 - 解码器的简称,做两个基本操作 - 首先,它将模拟语音信号转换为其等效数字形式,以便可以容易地发送. 此后,它将压缩的数字信号转换回其原始模拟形式,以便可以重放. 市场上有许多编解 ...