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);
    
    
    
    
    }
    
  • 相关阅读:
    图片采集
    资源(先备着)
    Memories of Vladimir Arnold 摘录
    Tribute to Vladimir Arnold 摘录
    Textbooks, Testing, Training: How We Discourage Thinking 笔记
    每天都有杰出数学家去世?(挖坑)
    I'm angry——人教B版选修2-3上的一个错误
    How to Study as a Mathematics Major 的笔记
    读《桑榆忆往》做的一点笔记
    《近代欧氏几何学》笔记
  • 原文地址:https://www.cnblogs.com/bhd123/p/9448957.html
Copyright © 2011-2022 走看看