Flying to the Mars

点我挑战题目

题意分析

有n个人,每个人都有一定的等级,高等级的人可以教低等级的人骑扫帚,并且他们可以共用一个扫帚,问至少需要几个扫帚。

这道题与最少拦截系统有异曲同工之妙。不同在于这道题可以排序,而最少拦截系统不能排序。我们想一下,把这些人排好序,并统计每个等级的人的个数。一次从最高等级到最低等级划掉一个人(可以理解为这些人互相教并且骑一个扫帚),一直划,直到最后一个人。这样可以看出来,扫帚的数量肯定是由某个等级的人数确定的。并且那个等级的人数最多。因此,只要统计出等数最多的等级就好,最后输出那个等级的人数。我采用了map映射,这样较为简单。

代码总览

/*
Title:HDOJ.1800
Author:pengwill
Date:2016-11-25
*/
#include <iostream>
#include <algorithm>
#include <map>
#include <stdio.h>
#define max 3005
using namespace std;
typedef map<int,int> mp;
mp p; mp::iterator iter; int main()
{
int n;
while(scanf("%d",&n) != EOF){
int i,temp;
for(i = 0;i<n;i++){
scanf("%d",&temp);
p[temp]++;
}
int nmax = 0;
for(iter = p.begin();iter != p.end();iter++){
if(iter->second > nmax){
nmax = iter->second;
//titer = iter;
}
}
p.clear();
printf("%d\n",nmax);
} return 0;
}

HDOJ.1800 Flying to the Mars(贪心+map)的更多相关文章

  1. 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 ...

  2. --hdu 1800 Flying to the Mars(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Ac code: #include<stdio.h> #include<std ...

  3. 杭电 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 ...

  4. hdu 1800 Flying to the Mars

    Flying to the Mars 题意:找出题给的最少的递增序列(严格递增)的个数,其中序列中每个数字不多于30位:序列长度不长于3000: input: 4 (n) 10 20 30 04 ou ...

  5. HDU 1800——Flying to the Mars——————【字符串哈希】

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  6. 【HDOJ】1800 Flying to the Mars

    1. 题目描述挺简单的一道题,给定$n$个大整数,求出现最多的次数. 2. 基本思路这题是可以使用哈希做,ELFHash等哈希都可以过. 3. 代码 /* 1800 */ #include <i ...

  7. HDU - 1800 Flying to the Mars 【贪心】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1800 题意 给出N个人的 level 然后 高的level 的 人 是可以携带 比他低level 的人 ...

  8. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  9. HDU 1800 Flying to the Mars Trie或者hash

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 题目大意: 又是废话连篇 给你一些由数字组成的字符串,判断去掉前导0后那个字符串出现频率最高. 一开始敲h ...

随机推荐

  1. Android性能测试 | 启动时间篇

    [转载]原文地址:http://www.51testing.com/html/93/n-3724593.html 背景介绍 Android用户也许会经常碰到以下的问题: 1)应用后台开着,手机很快没电 ...

  2. MySQL☞having子句

    having子句:是跟group  by结合使用,对分组以后的数据再次进行过滤,经常跟聚合函数结合使用 格式: select  列名/聚合函数 from  表名 where  条件 group  by ...

  3. springboot在application.yml中使用了context-path属性导致静态资源法加载,如不能引入vue.js,jquery.js,css等等

    在springBoot配置中加入上下文路径 server.context-path=/csdn js,img等静态文件无法加载,出现404的问题 <script type="text/ ...

  4. 初学DirectX(1)

    初学Direct X (1) Direct3D设备用于访问视频卡的帧缓冲区,以及后台缓冲区.由于IDE是vs2013,默认安装了direct 9,只需要在使用头文件(1)并像使用库文件(2)即可 #i ...

  5. mybatis interceptor 处理查询参数及查询结果

    拦截器:拦截update,query方法,处理查询参数及返回结果. /** * Created by windwant on 2017/1/12. */ @Intercepts({ @Signatur ...

  6. Python全栈 进阶(进阶内容都在这了)

    原文地址 https://yq.aliyun.com/articles/632754?spm=a2c4e.11155435.0.0.23eb3312feB6dG ................... ...

  7. ArrayList与LinkedList的普通for循环遍历

    对于大部分Java程序员朋友们来说,可能平时使用得最多的List就是ArrayList,对于ArrayList的遍历,一般用如下写法: public static void main(String[] ...

  8. php面试的那些“黑话”

    以下是一些常见的面试暗语,求职者一定要弄清楚其中蕴含的深意,不然可能“躺着也中枪”,最后只能铩羽而归. (1)请把简历先放在这,有消息我们会通知你的 面试官说出这句话,则表明他对你已经“兴趣不大”,为 ...

  9. [leetcode-779-K-th Symbol in Grammar]

    On the first row, we write a 0. Now in every subsequent row, we look at the previous row and replace ...

  10. Red and Black(DFS深搜实现)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...