HDU - 1800 Flying to the Mars 【贪心】

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1800

题意
给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 一起坐一把 魔法扫帚

要求所有人都有扫帚坐 求最少需要几把扫帚

思路
假如我们将数据大到小排序 第一次 将第一个人推入队列 然后后面的每一个人 只需要判断 先前有的队列 是否有队列可以让他入队 如果有 那么就让它入队 如果没有 就需要一个新的队列

但是这个算法 时间复杂度 比较高

其实 我们最后可以发现 我们只需要 求出 重复LEVEL的人 最多的 是多少 就需要多少把扫帚

AC代码

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<list>
#include<stack>
#include <queue>

#define CLR(a, b) memset(a, (b), sizeof(a))

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 3e3 + 5;
const int MOD = 1e10;


int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        map <int, int> m;
        int num;
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &num);
            m[num]++;
            ans = max(ans, m[num]);
        }
        printf("%d\n", ans);
    }
}

转载于:https://www.cnblogs.com/Dup4/p/9433104.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值