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. HTTP(HyperText Transport Protocol)超文本传输协议的状态码

    关于HTTP状态码:是用于表示网页服务器HTTP响应状态的3位数字代码. 所有状态码的第一个数字代表了响应的五种状态之一. 1xx:消息:这一类型的状态码代表请求已被接受,需要继续处理 2xx:成功: ...

  2. CodeForces 733C Epidemic in Monstropolis

    模拟. 连续的一段$a$合成一个$b$.每段中如果数字只有$1$个,那么可以合成.如果数字个数大于等于$2$个,如果都是一样的,那么无法合成,否则要找到一个可以移动的最大值位置开始移动.一开始写了一个 ...

  3. 洛谷——P2388 阶乘之乘

    P2388 阶乘之乘 题目背景 不告诉你…… 题目描述 求出1!*2!*3!*4!*……*n!的末尾有几个零 输入输出格式 输入格式: n(n<=10^8) 输出格式: 有几个零 输入输出样例 ...

  4. Unity做360度的全景照片

    这里推荐两种方法,第一种是用鼠标滑动,第二种是用手机的陀螺仪进行全景查看 第一种: 1.新建一Sphere,然后为其赋予材质,注意材质的Shader类型为:Mobile/particles/Alpha ...

  5. Python开发基础-Day11内置函数补充、匿名函数、递归函数

    内置函数补充 python divmod()函数:把除数和余数运算结果结合起来,返回一个包含商和余数的元组(a // b, a % b) 语法: divmod(a, b) #a.b为数字,a为除数,b ...

  6. 1. ECMAScript 6 简介--ES6

    1. ECMAScript 和 JavaScript 的关系 国际标准化组织ECMA 制定了语言 ECMAScript, 该标准针对 Javascript 语言制定, 不叫Javascript 原因有 ...

  7. ServletContext (上下文对象)

    一.什么是ServletContext ServletContext代表是一个web应用的上下文对象(web应用对象) 里面封装的都是web应用信息 一个ServletContext对应一个应用 二. ...

  8. HDU 2255 奔小康赚大钱(KM算法)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2255 [题目大意] 求最大匹配 [题解] KM模板 [代码] #include <cstdi ...

  9. 【二项式定理】【推导】计蒜客17115 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 B. Coin

    题意:投一枚硬币向上的概率是q/p.问你投K枚硬币,向上的枚数为偶数枚的概率是? 要求的即为. 这个东西是个二项展开式的偶数项系数和,来,我们复习一下高中数学,设f(x)=(ax+b)^n,则其偶数项 ...

  10. Vue实例详解与生命周期

    http://www.jianshu.com/p/b5858f1e6e76 Vue的实例是Vue框架的入口,其实也就是前端的ViewModel,它包含了页面中的业务逻辑处理.数据模型等,当然它也有自己 ...