CodeForces - 1011B Planning The Expedition
题意:
有n个人去探险,有m个食物,每人每天吃一个食物。如果某人第一天吃的食物种类为 a ,那么接下来的几天他只能吃食物种类为 a 的食物。求这些食物最多能吃几天。
思路:
将每一种食物的数量用 map 存储起来,遍历一遍找出最大天数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=1e6+10;
typedef long long ll;
map<int,int> ans;
int main()
{
int n,m;
int k;
scanf("%d%d",&n,&m);
int x;
for(int i=0;i<m;i++)
{
scanf("%d",&x);
ans[x]++;
}
if(n>m) //人比食物多
printf("0\n");
else
{
for(int i=1;i<=m;i++) // 从小到大枚举每一天
{
x = 0;
for(map<int,int>::iterator it=ans.begin();it!=ans.end();it++)
x += (it->second)/i; // 每天吃 i 个食物,能满足多少人
if(x>=n) // 人数 大于等于 n 满足条件
k = i; //保存最大天数
else
break;
}
printf("%d\n",k);
}
return 0;
}