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);
    
    
    
    
    }
    
  • 相关阅读:
    有关macOS隐藏文件的问题
    AcWing 2548. 大胖子走迷宫(BFS)
    AcWing 1224. 交换瓶子(交换最少次数使得数列有序)
    AcWing 1220. 生命之树(树形DP)
    AcWing 1215. 小朋友排队(树状数组)
    AcWing 1214. 波动数列(推柿子+DP)
    Python文件操作
    远程升级程序过程
    找某个Linux内核可能调用的文件
    linux platform简易的理解
  • 原文地址:https://www.cnblogs.com/bhd123/p/9448957.html
Copyright © 2011-2022 走看看