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);
}
}
HDU - 1800 Flying to the Mars 【贪心】的更多相关文章
- --hdu 1800 Flying to the Mars(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...
- hdu 1800 Flying to the Mars
Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...
- HDU 1800——Flying to the Mars——————【字符串哈希】
Flying to the Mars Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...
- HDU 1800 Flying to the Mars Trie或者hash
http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...
- hdu 1800 Flying to the Mars(简单模拟,string,字符串)
题目 又来了string的基本用法 //less than 30 digits //等级长度甚至是超过了int64,所以要用字符串来模拟,然后注意去掉前导零 //最多重复的个数就是答案 //关于str ...
- 杭电 1800 Flying to the Mars(贪心)
http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/Oth ...
- HDOJ.1800 Flying to the Mars(贪心+map)
Flying to the Mars 点我挑战题目 题意分析 有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚. 这道题与最少拦截系统有异 ...
- HDOJ 1800 Flying to the Mars 盲目搜索......................so easy...........
check the original problem here:http://acm.hdu.edu.cn/showproblem.php?pid=1800 the AC code: #include ...
随机推荐
- JDK与adb/android环境变量配置完整教程
在这篇文章中.主要解决一个在Java或者Android开发中第一步须要解决的问题,那就是环境变量的配置.因为这部分在网上有非常多教程.參差不齐.我这里主要是对JDK与adb/android两者的环境变 ...
- Iterative (non-recursive) Merge Sort
An iterative way of writing merge sort: #include <iostream> using namespace std; void merge(in ...
- mongoDB 使用总结
http://blog.chinaunix.net/space.php?uid=22270773&do=blog&id=19935171. 如果无特别用途,建议:表名,字段名 全部用小 ...
- window 服务(二)
接Window服务(一) ServiceController方法调用 public partial class Service1 : ServiceBase { public Service1() { ...
- asp.net core mvc视频A:笔记3-5.视图数据共享之TempData
前几节讲的都是单页面数据共享,从本节开始讲跨页面数据共享 创建项目3.5,新建控制器 代码 控制器 设置TempData 另一个视图中读取TempData数据 运行 此时如果刷新页面,页面中的内容“张 ...
- ASP.NET CORE RAZOR :将文件上传至 ASP.NET Core 中的 Razor 页面
本部分演示使用 Razor 页面上传文件. 本教程中的 Razor 页面 Movie 示例应用使用简单的模型绑定上传文件,非常适合上传小型文件. 有关流式传输大文件的信息,请参阅通过流式传输上传大文件 ...
- java中常用的类型转换
1.将字符串转换成整数(String--->int)方法一: (1) int i = Integer.parseInt(String s); 其中(1)其实就是我们经常用到的将s转换为10进 ...
- nginx适配移动端
考虑到网站的在多种设备下的兼容性,有很多网站会有手机版和电脑版两个版本.访问同一个网站URL,当服务端识别出用户使用电脑访问,就打开电脑版的页面,用户如果使用手机访问,则会得到手机版的页面. ngin ...
- [原创]个人工具 - 对APK极限压缩并对齐的工具(58.ReExtremeZipAndAlignAPK)
2014年9月13日:RootExplorer_v2.21.1_Aligned对齐后:在华为U8860(2.3.6).酷派8150S(4.0.3)上安装滑动列表时,崩溃.原版本(已对齐)则OK.(不知 ...
- 专用于高并发的map类-----Map的并发处理(ConcurrentHashMap)
oncurrentModificationException 在这种迭代方式中,当iterator被创建后集合再发生改变就不再是抛出ConcurrentModificationException, 取 ...