利用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,完成下面的功能: 从命令行读入一个字符串,表示一个年份,输出该年的世界杯冠军是哪支球队.如果该 年没有举办世界杯,则输出:没有举办世界杯. 附:世界杯冠军以及对应的夺冠年 ...
随机推荐
- 安装php5.5
安装php5.5 ./configure --prefix=/usr/local/php5.5.14/ --with-apxs2=/usr/local/apache2.2.27/bin/apxs -- ...
- hdu 1576 A/B (扩展欧几里德简单运用)
http://acm.hdu.edu.cn/showproblem.php?pid=1576 A/B Time Limit: 1000/1000 MS (Java/Others) Memory Lim ...
- nyoj 119 士兵杀敌(三)(RMQ)
士兵杀敌(三) 时间限制:2000 ms | 内存限制:65535 KB 难度:5 描述 南将军统率着N个士兵,士兵分别编号为1~N,南将军经常爱拿某一段编号内杀敌数最高的人与杀敌数最低的人进 ...
- POJ3185(简单BFS,主要做测试使用)
没事做水了一道POJ的简单BFS的题目 这道题的数据范围是20,所以状态总数就是(1<<20) 第一次提交使用STL的queue,并且是在队首判断是否达到终点,达到终点就退出,超时:(其实 ...
- IE浏览器在虚拟机中无法正常显示字符
今天在win7虚拟机中安装IE10之后,打开任何页面都无法显示文字,自己找了一些资料也没有什么发现,虚拟机其他的程序都能很好的工作,只有IE10有问题,于是初步怀疑是IE10设置的问题.于是打开IE的 ...
- WebSphere 集群环境下配置 Quartz集群
转载:http://hyamine.iteye.com/blog/397708 1. websphere工作管理器引用 WEB-INF/ibm-web-bnd.xmi <?xml version ...
- 备份Xcode6的配色主题以及代码模板
~/Library/Developer/Xcode/UserData/FontAndColorThemes ~/Library/Developer/Xcode/UserData/CodeSnippet ...
- easyui中tree型控件不正常显示的处理方法
我在使用easyui中的tree控件时,出现不正常显示的现象,比如li中不能使用自定义的图标.父级展开或关闭时,其子级仍然显现并出现重叠等.找了很多资料,都没解决这个问题,后来逐个对照官方的源码,才找 ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]
3.2 Create创建用户 [HttpPost, Authorize] public async Task<ActionResult> Create( [Bind(Include = & ...
- 切取图片的一部分(利用CCRenderTexture)
转自:http://blog.csdn.net/wcjwdq/article/details/37932769 显示图片时,在项目中经常会用只读取图片的一部分,而不是全部. 错误方式:很多人这时候会采 ...