CodeForces - 1011B Planning The Expedition

15 篇文章 1 订阅

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值