Flying to the Mars

          Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                Total Submission(s): 4318    Accepted Submission(s): 1393

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

根据题意可知:意思是有若干个飞行员,需要在扫帚上练习飞行,每个飞行员具有不同的等级,且等级高的飞行员可以当等级低的飞行员的老师,且每个飞行员至多有且只有一个老师和学生。具有老师和学生关系的飞行员可以在同一把扫帚上练习,并且这个性质具有传递性。即比如有A,B,C,D,E五个飞行员,且等级是A>B>C>D>E,那么可以使A当B的老师,B当C的老师,E当D的老师,那么A,B,C可以在同一扫帚上练习,D,E在同一把扫帚上练习,这样需要2把扫帚,而如果是A当B的老师,B当C的老师,C当D的老师,D当E的老师,那么只需要一把扫帚。题目所求即所需最少的扫帚数目。

假设有若干个飞行员,{{A1,A2,A3...AK},{B1,B2,B3,...Bm}......{F1,F2,F3.....Fn}}。其已经按照等级由低到高排好序,在同一个集合里的飞行员等级相同。若需要最少数目的扫帚,则只能是{A1,B1.....F1},{A2,B2....F2}..这样进行组合,扫帚数目最少。因此决定所需最少扫帚数目的集合是含有飞行员最多的集合,即同一等级数目最多的飞行员集合。因此可以采用STL中的map直接实现。
实现代码:
/*hdu 1800 最大分配 2011.10.12*/ #include <iostream>#include<map>using namespace std;

int main(int argc, char *argv[]){int n;while(scanf("%d",&n)==1)    {int i;        map<int,int> mp;int max=INT_MIN;for(i=0;i<n;i++)        {int level;            scanf("%d",&level);            mp[level]++;if(mp[level]>max)            {                max=mp[level];                                 }        }        printf("%d\n",max);    }return 0;} 

转载于:https://www.cnblogs.com/dolphin0520/archive/2011/10/12/2209023.html

hdu 1800 Flying to the Mars相关推荐

  1. hdu 1800 Flying to the Mars

    Flying to the Mars Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

  2. 1800 Flying to the Mars 大数 最多不上升序列 简化题意

    Flying to the Mars Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. hdu 1800 (map)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1800 Flying to the Mars Time Limit: 5000/1000 MS (Java/ ...

  4. Flying to the Mars

    题目描述 In the year 8888, the Earth is ruled by the PPF Empire . As the population growing , PPF needs ...

  5. HDU 4059 The Boss on Mars (容斥)(2011 Asia Dalian Regional Contest)

    The Boss on Mars 思路 显然我们可以求得∑i=1ni4=6n5+15n4+10n3−n30\sum_{i = 1} ^{n} i ^ 4 = \frac{6n^5 + 15n^4 + ...

  6. HDOJ1800 Flying to the Mars【Hash】

    题目大意: 8888年,地球被PPF王国统治了.由于人口增长,PPF需要为新生儿找寻更多的陆地.最后,PPF决定攻击通知Mars火星的Kscinow.问题来了,怎样让士兵到火星上去呢?PPF召集士兵征 ...

  7. hdu 4059 The Boss on Mars

    题意 求1到之间所有与n互质的数的四次幂之和. 分析 分解n^5-(n-1)^5..可以求出1^4+2^4+...+n^4的公式S(n)=1/30*(n^5+15*n^2*(n+1)^2-10*n*( ...

  8. HDU 1800(字典树)

    简单的字典树水题,统计为单词前缀的单词数,取最大,注意要去前0,具体原理还是自己想想吧,最大数决定了最大分组. 诶 PKU月赛之后 我发现我只会水的 .............. #include&l ...

  9. hdu 4059 The Boss on Mars 容斥

    题目链接 求出ai^4+a2^4+......an^4的值, ai为小于n并与n互质的数. 用容斥做, 先求出1^4+2^4+n^4的和的通项公式, 显然是一个5次方程, 然后6个方程6个未知数, 我 ...

最新文章

  1. 快乐学习Pandas!开源教程《Joyful-Pandas》发布
  2. Nacos支持配置的动态更新
  3. linux usb filesystem
  4. LeetCode 第 206 场周赛(733/4491,前16.3%)
  5. Java Web实训项目:西蒙购物网(中)
  6. 补交20145226蓝墨云班课 -- MyCP
  7. 判断objcet是否是map类型_Java集合类和Map判定一个对象是否已经存在
  8. 【资料】《数字电子技术基础》阎石第五版
  9. Protues 8.8 SP1 无需破解 可用直装版 指路
  10. scipy的安装教程
  11. eNews 第二十五期/2007.06
  12. Proteus与keil联合仿真
  13. 程序员面试阿里、腾讯、京东等大公司,这些套路你知道吗?
  14. 腾讯地图实现站点标记,及已标记的点回显在地图上
  15. Matlab的plot函数画线显示空白问题解决
  16. ic和mos怎么区分_MOS管和IGBT管的定义是什么与怎么辨别呢?
  17. Docker学习(四):Dockerfile
  18. RALL原则和unique_ptr
  19. 骚操作!公司招聘运营称已婚双休未婚单休
  20. vb.net listview 删除选定行_VBA学习笔记59-1: listview控件

热门文章

  1. Bokeh 添加注释
  2. linux ssh原理
  3. 使用工具Csvde导出域中所有用户信息
  4. VMware vSAN网络设计中不得不说的事
  5. 如何在VMware软件上安装Red hat(红帽)Linux6.9操作系统
  6. Spring Boot学习总结(30)—— Spring Native 初体验
  7. python字符编码正确的是_python字符编码
  8. qpushbutton 添加本地文件图标_1.PyQt5实现多文件调用以及UI和逻辑分离
  9. Mariadb学习总结(十二):复合语句和流程控制
  10. EOS cleos --skip-transaction-signatures 跳过签名