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
解题:仅仅要求出数字出现最多的次数。 当n=0时。输出1.
#include<stdio.h>
#include<malloc.h>
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;
typedef struct nn
{
int num,flag;
struct nn *next[10];
}node;
node *builde()
{
node *p=(node*)malloc(sizeof(node));
p->num=0; p->flag=0;
for(int i=0;i<10;i++)
p->next[i]=NULL;
return p;
}
node *root;
int insert(char ans[])
{
node *p=root;
int i=0;
while(ans[i]=='0')i++;
while(ans[i]!='\0')
{
if(p->next[ans[i]-'0']==NULL)
p->next[ans[i]-'0']=builde();
p=p->next[ans[i]-'0'];
i++;
}
p->flag=1; p->num++;
return p->num;
}
int main()
{
int n,max;
char ans[35];
while(scanf("%d",&n)>0)
{
max=0;
root=builde();
while(n--)
{
scanf("%s",ans);
int t=insert(ans);
if(t>max)max=t;
}
if(max==0)max=1;
printf("%d\n",max);
}
}

hdu1800Flying to the Mars (字典树)的更多相关文章

  1. HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树

    http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...

  2. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  3. hdu 1075(字典树)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  4. Tire树(字典树)

    from:https://www.cnblogs.com/justinh/p/7716421.html Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,P ...

  5. J - What Are You Talking About(map,字典树)

    题意:上部分是单词表,下部分是句子,翻译句子.START开始,END结束. 思路:简单字典树. Ignatius is so lucky that he met a Martian yesterday ...

  6. 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)

    前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...

  7. [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)

    Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...

  8. 字典树+博弈 CF 455B A Lot of Games(接龙游戏)

    题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...

  9. 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)

    萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...

随机推荐

  1. java网络通信:HTTP协议 之 Sessions与Cookies

    通过前一篇博客的讲解,我们大体知道了HTTP协议是什么,它有什么组成,以及它的工作原理,那么在HTTP的很多特点中,有一点叫做,无状态,就HTTP是一个无状态的协议,如果需要前面的信息用于处理后边的请 ...

  2. mocha测试es6问题

    平时在写完正常的逻辑代码后,需要使用单元测试去测试逻辑代码,现在比较流行的是使用mocha进行测试 现在都是使用es6的写法,如果直接使用mocha test\某个文件,会出现下面的错误,原因是因为m ...

  3. QT库在Windows上的编译

    1.从http://www.qtcentre.org/下载QT源代码,注意是源代码.我下载到的是QT4.5.1版,文件名为qt-win-opensource-src-4.5.1.zip: 2.解压,注 ...

  4. python之md5模块

    python的md5模块使用非常简单,包括以下几个函数: md5.new([arg]) 返回一个md5对象,如果给出参数,则相当于调用了update(arg) md5.updte(arg) 用stri ...

  5. 战火魔兽CJQ圣印问题

    本来一直是玩的T的. 一次偶然机会打了次团本,用CJQ(毒蛇),在副本中问CJQ用什么圣印 有人说命令,有人说腐蚀... 对此做先研究 无BUFF木桩测试:5分钟(开sp翅膀,不踩奉献,技能什么好了按 ...

  6. HRBUST 1311 火影忍者之~忍者村

    求连通块. $ABC$之间建好边,然后计算连通块的个数. #pragma comment(linker, "/STACK:1024000000,1024000000") #incl ...

  7. CodeForces 738E Subordinates

    排序,构造. 相当于告诉我们一棵树$n$个节点,每个节点在哪一层,至少需要移动多少个节点,才能让这些节点变成一棵树. 按照层次排个序移动一下就可以了,优先选择那些不是$s$但是层次是$0$的节点,如果 ...

  8. sg函数总结

    http://blog.csdn.net/luomingjun12315/article/details/45555495 这一段时间写的题和我接下来要展示的一些概念都来自这里↑. 必胜点和必败点的概 ...

  9. Java编程思想学习(一)----对象导论中多态的理解

    1.1抽象过程 1)万物皆对象. 2)程序是对象的集合,他们通过发送消息来告知彼此所要求做的. 3)每个对象都有自己的由其他对象所构成的存储. 4)每个对象都拥有其类型. 5)某一特定类型的所有对象都 ...

  10. 20172333 2017-2018-2 《Java程序设计》第8周学习总结

    20172333 2017-2018-2 <Java程序设计>第8周学习总结 教材学习内容 多态性应用可以随时间变化指向不同类型的对象. 多态性应用,方法的引用与方法的定义代码的绑定在运行 ...