利用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,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
随机推荐
- Linux下的设置静态IP命令详解
网络配置的配置文件在/etc/sysconfig/network-scripts/下,文件名前缀为ifcfg-后面跟的就是网卡的名称,可以通过双TAB键查看然后编辑,也可以使用ifconfig查看,也 ...
- spring 解析配置文件问题
问题描述 2014-02-25 16:39:36.068 [com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2] WARN ...
- Cisco ASA5500系列防火墙恢复IOS全过程
擦除防火墙配置的命令是write erase而不是erase flash!当ASA5510的flash被erase后,如何将新的IOS拷贝到5510内呢? 如下:1. 当flash被erase后设备会 ...
- Android - 应用名称设置的问题
今天我想修改我的android应用名称,就是手机桌面上图标下面的名称,根据我的理解我修改AndroidManifest.xml文件中application标签中的android:label=" ...
- 关于dll的路径问题
最近在做一个sdk二次开发的项目,具体是将一个C++开发的SDk用C#将它的API接口全部封装一遍,然后再做一个demo就好了 好不容易封装完了,在使用的时候出了问题.原来SDK中的dll老是加载不到 ...
- JavaScript神一样的变量系统
话说上一篇介绍了JavaScript故事版的身世之谜.看官你估计也明白JavaScript出生之时,就未曾托于重任.布兰登-艾奇估计也没料到今天的JavaScript变得如此重要.要不然,当年他也不会 ...
- mysql中间件研究(Atlas,cobar,TDDL)
mysql-proxy是官方提供的mysql中间件产品可以实现负载平衡,读写分离,failover等,但其不支持大数据量的分库分表且性能较差.下面介绍几款能代替其的mysql开源中间件产品,Atlas ...
- Rank() over(partition ... 分组统计的实例
USE [NanFeng]GO/****** Object: StoredProcedure [dbo].[st_MES_RptMaterilSum] Script Date: 04/18/2016 ...
- VC++ 6.0中实现三叉切分窗口与多视图 [转]
一.引用 当用户需要同时对文当的不同部分进行编辑时,常常会用到切分窗口;这些窗口可以都是相同的视,或者一个窗口为列表视,而另一个为树型视图.应用程序框架有多种方式来表示多视图,切分窗口是其中的方式之一 ...
- cmd命令。
CMD按任意退出 echo 退出……按任意键pause & exit