Problem Description

In the year 8888, the
Earth is ruled by the PPF Empire . As the population growing , PPF needs to find
more land for the newborns . Finally , PPF decides to attack Kscinow who ruling
the Mars . Here the problem comes! How can the soldiers reach the Mars ? PPF
convokes his soldiers and asks for their suggestions . “Rush … ” one soldier
answers. “Shut up ! Do I have to remind you that there isn’t any road to the
Mars from here!” PPF replies. “Fly !” another answers. PPF smiles :“Clever guy !
Although we haven’t got wings , I can buy some magic broomsticks from HARRY
POTTER to help you .” Now , it’s time to learn to fly on a broomstick ! we
assume that one soldier has one level number indicating his degree. The soldier
who has a higher level could teach the lower , that is to say the former’s level
> the latter’s . But the lower can’t teach the higher. One soldier can have
only one teacher at most , certainly , having no teacher is also legal.
Similarly one soldier can have only one student at most while having no student
is also possible. Teacher can teach his student on the same broomstick
.Certainly , all the soldier must have practiced on the broomstick before they
fly to the Mars! Magic broomstick is expensive !So , can you help PPF to
calculate the minimum number of the broomstick needed .
For example :

There are 5 soldiers (A B C D E)with level numbers : 2 4 5 6 4;
One
method :
C could teach B; B could teach A; So , A B C are eligible to study
on the same broomstick.
D could teach E;So D E are eligible to study on the
same broomstick;
Using this method , we need 2 broomsticks.
Another
method:
D could teach A; So A D are eligible to study on the same
broomstick.
C could teach B; So B C are eligible to study on the same
broomstick.
E with no teacher or student are eligible to study on one
broomstick.
Using the method ,we need 3 broomsticks.
……

After
checking up all possible method, we found that 2 is the minimum number of
broomsticks needed.

 
Input
Input file contains multiple test cases.
In a test
case,the first line contains a single positive number N indicating the number of
soldiers.(0<=N<=3000)
Next N lines :There is only one nonnegative
integer on each line , indicating the level number for each soldier.( less than
30 digits);
 
Output
For each case, output the minimum number of broomsticks
on a single line.
 
Sample Input
4
10
20
30
04
5
2
3
4
3
4
 
Sample Output
1
2
 
这道题的思路还是挺简单的,就是寻找所有数中出现次数最大的那一个数,但是上面说最长达到了30位数,所以用普通的排序做不了,这时候可以用map容器来做,map容器的内部是一个红黑树,我们是在对它的叶节点进行操作,一共有两个数,第二个数是作为计数用的。
 
 #include <map>
using namespace std; int main(){
int number;
int i;
int level;
int max; while(scanf("%d",&number)!=EOF){
max=; map<int,int> mp;
for(i=;i<number;i++){
scanf("%d",&level);
mp[level]++; if(mp[level]>max)
max=mp[level];
} printf("%d\n",max);
} return ;
}
 

利用map可以对很大的数出现的次数进行记数的更多相关文章

  1. 剑指offer:数组中出现次数超过一半的数

    题目描述: 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2 ...

  2. string::npos,一个很大的数

    string::npos,这是一个很大的数 npos 是这样定义的: static const size_type npos = -1; 因为 string::size_type (由字符串配置器 a ...

  3. 快速幂取模(当数很大时,相乘long long也会超出的解决办法)

    当几个数连续乘最后取模时,可以将每个数字先取模,最后再取模,即%对于*具有结合律.但是如果当用来取模的数本身就很大,采取上述方法就不行了.这个时候可以借鉴快速幂取模的方法,来达到大数相乘取模的效果. ...

  4. W - Doom HDU - 5239 线段树 找取模的规律+求一个很大的数的平方对一个数取模的写法 特别的模数==2^63-2^31

    这个题目一开始感觉还是有点难的,这个模数这么大,根本就不知道怎么写,然后去搜了题解,知道了怎么去求当x很大的时候x的平方对一个数取模怎么样不会爆掉. 然后还顺便发现了一个规律就是当一个数更新一定次数之 ...

  5. 【SecureCRT配置】修改默认卷屏行数当做一个操作,屏幕输出有上百行,当需要将屏幕回翻时,这个设置会有很大帮助,默认为500行,可以改为10000行,不用担心找不到了。 选项 => 全局选项 => Default Session => Edit Default Settings => Terminal => Emulation => Scrollback 修改为32000。

    SecureCRT配置屏幕内容输出到log文件 SecureCRT看不到前几分钟操作的内容,或者想把通过vi命令查看的日志输出到log文件(在懒得下载日志文件的情况下),所以接下来就这样操作: 文件保 ...

  6. mysql5.6启动占用内存很大的解决方法

    vps的内存为512M,安装好nginx,php等启动起来,mysql死活启动不起来看了日志只看到对应pid被结束了,后跟踪看发现是内存不足被killed; 调整my.cnf 参数,重新配置(系统默认 ...

  7. 李洪强iOS经典面试题30-一个区分度很大的面试题

    李洪强iOS经典面试题30-一个区分度很大的面试题 考察一个面试者基础咋样,基本上问一个 @property 就够了: @property 后面可以有哪些修饰符? 线程安全的: atomic,nona ...

  8. 利用MySQL数据库如何解决大数据量存储问题?

    提问:如何设计或优化千万级别的大表?此外无其他信息,个人觉得这个话题有点范,就只好简单说下该如何做,对于一个存储设计,必须考虑业务特点,收集的信息如下:1.数据的容量:1-3年内会大概多少条数据,每条 ...

  9. Java-map-第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录

    第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...

随机推荐

  1. C#完整的通信代码(点对点,点对多,同步,异步,UDP,TCP)

    C# code namespace UDPServer { class Program { static void Main(string[] args) { int recv; byte[] dat ...

  2. redhat6.4升级openssh至6.7

    1:简介 最近浙江电信对线上服务器进行漏洞扫描,暴露出原有的openssh有漏洞,建议升级openssh版本: 2:操作环境 Red Hat Enterprise Linux Server relea ...

  3. [原创]mac终端前面的计算机名怎么改??

    1.修改-之前的名称 mac环境,系统 OS X Yisemite,打开终端, 执行下面命令“Tmp”是你想要改的电脑名称 sudo scutil --set HostName Tmp 执行前,执行后 ...

  4. C#中自定义消息,与MFc对比

    在C#中采用的是事件驱动方式,但在我们使用的过程中,有时候通过调用系统原有的消息,处理起来会比较简单一些,特别是在处理与DLL文件的交互时,的确是非常的方便.    在C#中使用自定义消息      ...

  5. 编译安装-Apache

    一.配置选项说明 二.安装apache 1.环境准备 2.安装apr 3.安装apr-util 4.安装pcre 5.安装httpd 6.修改配置文件 7.开机自启动 8.注册为服务 9.测试 一.配 ...

  6. Elasticsearch template configuration

    Index templates allow defining templates thatwill automatically be applied to new indices created. T ...

  7. 【百题留念】hdoj 1524 A Chess Game(dfs + SG函数应用)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1524 #include<stdio.h> #include<cstring> ...

  8. java dbcp连接池的使用

    package com.jb.jubmis.comm; import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQL ...

  9. Java中返回参数值的几种状态

    Java 中无参无返回值方法的使用 第一步,定义方法 例如:下面代码定义了一个方法名为 show ,没有参数,且没有返回值的方法,执行的操作为输出 " welcome to imooc. & ...

  10. [读书笔记]SQL约束

    目的:通过在列级或表级设置约束,确保数据符合某种数据完整性规则 实现:数据库主动地检查维护数据的完整性 手段:约束,数据类型,触发器 --------------------------------- ...