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);
    }
}
posted @ 2018-04-13 22:52  Dup4  阅读(100)  评论(0编辑  收藏  举报