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. thinkphp图片上传+validate表单验证+图片木马检测+缩略图生成

    目录 1.案例 1.1图片上传  1.2进行图片木马检测   1.3缩略图生成   1.4控制器中调用缩略图生成方法 1.案例 前言:在thinkphp框架的Thinkphp/Library/Thin ...

  2. NBUT 1220 SPY

    $map$,简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...

  3. scrapy抓取拉勾网职位信息(三)——爬虫rules内容编写

    在上篇中,分析了拉勾网需要跟进的页面url,本篇开始进行代码编写. 在编写代码前,需要对scrapy的数据流走向有一个大致的认识,如果不是很清楚的话建议先看下:scrapy数据流 本篇目标:让拉勾网爬 ...

  4. 谜题54:Null与Void

    下面仍然是经典的Hello World程序的另一个变种.那么,这个变种将打印什么呢? public class Null { public static void greet() { System.o ...

  5. 桌面笔记工具KeepNote

    桌面笔记工具KeepNote   在渗透测试过程中,安全人员经常需要记录各种数据,如输出结果.运行截图.测试心得.这类信息格式多样,可能是图片.文字.文件等.为了便于管理这些内容,Kali Linux ...

  6. [BZOJ3131] [Sdoi2013]淘金

    [BZOJ3131] [Sdoi2013]淘金 Description 小Z在玩一个叫做<淘金者>的游戏.游戏的世界是一个二维坐标.X轴.Y轴坐标范围均为1..N.初始的时候,所有的整数坐 ...

  7. 【最短路】【spfa】CDOJ1647 酌贪泉而觉爽, 处涸辙以犹欢。

    题意: 给你一个全为0的01串,问你能否通过一系列的变换,得到全为1的01串. 分析: 将每个01串看作一个点,每一个变换可以看作是一条有向边,现在问题可以转化 为找从“00..0”这个点到“11.. ...

  8. NHibernate 继承映射(第十六篇)

    在NHibernate的映射中,关于继承的映射策略有3种方式 单表继承 类表继承 具体表继承 另外还有一种比较特别的多态映射 隐式多态 下面分别来阐述NHibernate继承映射的各种策略要点. 一. ...

  9. GCC,LLVM,Clang编译器对比

    http://www.cnblogs.com/qoakzmxncb/archive/2013/04/18/3029105.html   在XCode中,我们经常会看到这些编译选项(如下图),有些人可能 ...

  10. 各种GCC

    Cross GCC Cygwin GCC Linux GCC MacOSX GCC MinGW GCC Solaris GCC Clang