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. 第二百一十一天 how can i 坚持

    参与感.做项目要有激情. 睡觉.

  2. 为什么在Spring的配置里,最好不要配置xsd文件的版本号

    为什么dubbo启动没有问题? 原文链接:http://www.tuicool.com/articles/YRn67zM 这篇blog源于一个疑问: 我们公司使了阿里的dubbo,但是阿里的开源网站h ...

  3. Uber新功能:隐藏司机乘客们的手机号码

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  4. 关于Ext.NET Demo程序在IIS7.5部署出现"Ext未定义"的解决方案

    有以下三点 1.应用程序池请用ASP.NET4.0经典模式 2.安装ASP.NET   控制面板-->程序和功能-->打开或关闭WIndows功能-->Internet信息服务--& ...

  5. -g vs -rdynamic

    [-g vs -rdynamic] -g选项与-rdynamic选项的差别:1,-g选项新添加的是调试信息(一系列.debug_xxx段),被相关调试工具,比如gdb使用,可以被strip掉. 2,- ...

  6. Wisdombud.CommonTool及其应用

    @(编程) 1. 用法 student类 using System.ComponentModel; namespace WindowsFormsApplication1 { public class ...

  7. MVC 小常识

    什么是MVC (模型 视图 控制器)? MVC是一个架构模式,它分离了表现与交互.它被分为三个核心部件:模型.视图.控制器.下面是每一个部件的分工: 视图是用户看到并与之交互的界面. 模型表示业务数据 ...

  8. OC键值观察KVO

    什么是KVO? 什么是KVO?KVO是Key-Value Observing的简称,翻译成中文就是键值观察.这是iOS支持的一种机制,用来做什么呢?我们在开发应用时经常需要进行通信,比如一个model ...

  9. C\C++编程中:相对路径+绝对路径

    电脑硬盘E盘下,建文件夹“test”,"test"下建立子文件夹“file”,"file"下建子文件夹“data”, 电脑资源管理器显示目录  E:\test\ ...

  10. Painter 12安装教程

    1 首先打开激活器 2 开始安装,点击我有序列码,把激活器中的序列码粘贴到安装文件中. 3 安装完成后,点击activate option选项,点击电话联系: 激活成功