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);
    
    
    
    
    }
    
  • 相关阅读:
    Qt编程规范
    QtZint编译过程记录(要使用 QTMAKE_CFLAGS += /TP 参数)
    中科同向备份软件Heartsone-backup(足足16个软件,可差异化备份虚拟机)
    单例(Singleton)模式
    COFF/PE文件结构
    模板样式优化
    如何测试网页的登录页面
    enode框架step by step之消息队列的设计思路
    服务承载
    CSS文件和Javascript文件的压缩
  • 原文地址:https://www.cnblogs.com/bhd123/p/9448957.html
Copyright © 2011-2022 走看看