zoukankan      html  css  js  c++  java
  • map迭代器有点好用

    Natasha is planning an expedition to Mars for n

    people. One of the important tasks is to provide food for each participant.

    The warehouse has m

    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 j

    Natasha should select his food type bj and each day j-th participant will eat one food package of type bj. The values bj

    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 n

    and m (1n100, 1m100

    ) — the number of the expedition participants and the number of the daily food packages available.

    The second line contains sequence of integers a1,a2,,am

    (1ai100), where ai is the type of i

    -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.

    #include <set>
    #include <map>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int cmp(int a,int b)
    {
        return a>b;
    }
    int main()
    {
        map<int,int>mp;
        map<int,int>::iterator it;
        int n,m,b;
        int a[150],i;
        scanf("%d%d",&n,&m);
        for(i=0; i<=m-1; i++)
        {
            scanf("%d",&b);
            mp[b]++;
        }
        int t=0;
        for(it=mp.begin(); it!=mp.end(); it++)
        {
            a[t++]=it->second;
    
        }
        sort(a,a+t,cmp);
        int maxx=1;
        int flag;
        for(i=a[0]; i>=1; i--)
        {
            flag=0;
            int ge=0;
            for(int j=0; j<=t-1; j++)
                ge+=a[j]/i;
            if(ge>=n)
            {
                maxx=i;
                flag=1;
                break;
            }
        }
        if(flag==0)
            printf("0
    ");
        else
            printf("%d
    ",maxx);
    
    
    
    
    }
    
  • 相关阅读:
    C++第7周任务3输出星号图详解示例
    C++第7周任务3输出星号图全解
    C02程序设计基础提高班(C++)第7周上机任务指针
    毕业生反馈(三)
    C++程序设计第七周上机实践项目
    C03Java同步实践加强班第7周上机任务
    写给菜鸟:发CSDN博文常见问题处理
    android项目 添加
    编译某一个ko模块make modules SUBDIRS=drivers/xxx/
    修改其他输入法为android 默认输入法
  • 原文地址:https://www.cnblogs.com/bhd123/p/9448957.html
Copyright © 2011-2022 走看看