利用map可以对很大的数出现的次数进行记数

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.
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);
on a single line.
20
30
04
3
4
3
4
#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可以对很大的数出现的次数进行记数的更多相关文章
- 剑指offer:数组中出现次数超过一半的数
题目描述: 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2 ...
- string::npos,一个很大的数
string::npos,这是一个很大的数 npos 是这样定义的: static const size_type npos = -1; 因为 string::size_type (由字符串配置器 a ...
- 快速幂取模(当数很大时,相乘long long也会超出的解决办法)
当几个数连续乘最后取模时,可以将每个数字先取模,最后再取模,即%对于*具有结合律.但是如果当用来取模的数本身就很大,采取上述方法就不行了.这个时候可以借鉴快速幂取模的方法,来达到大数相乘取模的效果. ...
- W - Doom HDU - 5239 线段树 找取模的规律+求一个很大的数的平方对一个数取模的写法 特别的模数==2^63-2^31
这个题目一开始感觉还是有点难的,这个模数这么大,根本就不知道怎么写,然后去搜了题解,知道了怎么去求当x很大的时候x的平方对一个数取模怎么样不会爆掉. 然后还顺便发现了一个规律就是当一个数更新一定次数之 ...
- 【SecureCRT配置】修改默认卷屏行数当做一个操作,屏幕输出有上百行,当需要将屏幕回翻时,这个设置会有很大帮助,默认为500行,可以改为10000行,不用担心找不到了。 选项 => 全局选项 => Default Session => Edit Default Settings => Terminal => Emulation => Scrollback 修改为32000。
SecureCRT配置屏幕内容输出到log文件 SecureCRT看不到前几分钟操作的内容,或者想把通过vi命令查看的日志输出到log文件(在懒得下载日志文件的情况下),所以接下来就这样操作: 文件保 ...
- mysql5.6启动占用内存很大的解决方法
vps的内存为512M,安装好nginx,php等启动起来,mysql死活启动不起来看了日志只看到对应pid被结束了,后跟踪看发现是内存不足被killed; 调整my.cnf 参数,重新配置(系统默认 ...
- 李洪强iOS经典面试题30-一个区分度很大的面试题
李洪强iOS经典面试题30-一个区分度很大的面试题 考察一个面试者基础咋样,基本上问一个 @property 就够了: @property 后面可以有哪些修饰符? 线程安全的: atomic,nona ...
- 利用MySQL数据库如何解决大数据量存储问题?
提问:如何设计或优化千万级别的大表?此外无其他信息,个人觉得这个话题有点范,就只好简单说下该如何做,对于一个存储设计,必须考虑业务特点,收集的信息如下:1.数据的容量:1-3年内会大概多少条数据,每条 ...
- Java-map-第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队。如果该 年没有举办世界杯,则输出:没有举办世界杯。 附:世界杯冠军以及对应的夺冠年份,请参考本章附录。 附录
第一题 (Map)利用Map,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
随机推荐
- <转>单播,广播,组播的缺点与优点
原文链接:http://apje.blog.163.com/blog/static/145345252007101175714761/ 当前的网络中有三种通讯模式:单播.广播.组播(多播),其中的组播 ...
- Linux下的grep搜索命令详解(二)
grep与正规表达式 字符类 字符类的搜索:如果我想要搜寻 test 或 tast 这两个单词时,可以发现到,其实她们有共通的 't?st' 存在-这个时候,我可以这样来搜寻: [root@www ...
- spring MVC 如何查找URL对应的处理类
在spring 3.1之前,查找URL相应的处理方法,需要分两步,第一步是调用DefaultAnnotationHandlerMapping,查找到相应的controller类,第二步,再调用Anno ...
- 给windows 7安装文件添加USB3.0驱动
给Air安装win7进入语言与区域选择之后,发现键盘触摸板都失灵. 原因:新款的 Macbook Air 2013 因为使用了 USB3.0 端口键盘和触摸板设备,所以在安装 Windows 7 ...
- iOS开发中的测试框架
转载作者:@crespoxiao 我们为什么要用测试框架呢?当然对项目开发有帮助了,但是业内现状是经常赶进度,所以TDD还是算了吧,BDD就测测数据存取和重要环节,这很重要,一次性跑完测试单元检查接口 ...
- 接口是干爹, 继承是亲爹 ---JAVA
接口(interface)是干爹, 因为你可以有很多很多的干爹爹... 继承(extends)是亲爹, 因为你只能有一个父类, 只有一个亲生的父亲. 单继承,多接口?./>./..
- HDU1896Stones(优先队列)
地址http://acm.hdu.edu.cn/showproblem.php?pid=1896 题目大一比较简单,就是说在一条直线道路上有n个石头,往前走,遇到一个数一个,如果遇到的是第奇数个那就把 ...
- css 精灵的用法
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-02-12) 是指将多个图整合到一张图上,避免多次请求服务器下载. 主要使用CSS background-position 属 ...
- 前端相关的seo技术
相信大部分的前端开发人员应该深知seo对我们的重要性,所以个人认为平台在开发初期就应该要考虑好seo优化的问题,不然做出来的页面,就算是效果很炫,功能很强,但是对搜索引擎也不友善.如果等到成熟时期再来 ...
- 分享一个导出Excel时页面不跳转的小技巧
今天在点击客户档案导出的时候,发现先是打开了一个新标签,然后新标签自动关掉,弹出一个文件下载确认的窗口,点击确认后开始下载导出的Excel文件.这样的过程感觉窗口闪来闪去,而且可能会给用户带来困惑,是 ...