hdu1800Flying to the Mars (字典树)

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 .
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);
4
10
20
30
04
5
2
3
4
3
4
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 (字典树)的更多相关文章
- HDU 1800 Flying to the Mars 字典树,STL中的map ,哈希树
http://acm.hdu.edu.cn/showproblem.php?pid=1800 字典树 #include<iostream> #include<string.h> ...
- hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- hdu 1075(字典树)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- Tire树(字典树)
from:https://www.cnblogs.com/justinh/p/7716421.html Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,P ...
- J - What Are You Talking About(map,字典树)
题意:上部分是单词表,下部分是句子,翻译句子.START开始,END结束. 思路:简单字典树. Ignatius is so lucky that he met a Martian yesterday ...
- 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
- 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)
萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...
随机推荐
- mysql查询优化以及面试小结
mysql面试小结: 1.mysql的基本架构 2.mysql的索引 btree+的原理 3.mysql的索引优化 4.mysql的sql查询优化 慢查询日志 Show prodile 全局查询日志 ...
- 线段树+哈希【CF580E】Kefa and Watch
线段树+哈希[CF580E]Kefa and Watch Description \(n\)个数的字符串,\(m + k\)个操作 1 l r k把\(l - r\)赋值为\(k\) 2 l r d询 ...
- Linux前后台进程切换
(1).Linux前台进程与后台进程的区别 前台进程:是在终端中运行的命令,那么该终端就为进程的控制终端,一旦这个终端关闭,这个进程也随之消失. 后台进程:也叫守护进程(Daemon),是运行在后台的 ...
- python 打包详解
基本步骤: 1. 写setup.py 2. 运行“python setup.py sdist” 3. 在当前目录下会生成文件夹“dist”,打包好的代码就在dist中,以“.tar.gz”的形式被压缩 ...
- [BZOJ2595]游览计划
斯坦纳树居然不是数据结构... 斯坦纳树应该是类似最小生成树的问题,只不过它允许增加额外的点 比如这道题就是找关于景点的最小生成树,但还要付出最小的代价,加一些额外的格子把景点都连起来 套路是设$f_ ...
- idea自动生成spring实体
创建Spring Boot项目 idea创建新项目 File->New->Project选择Spring Initializr默认使用官方的https://start.spring.io/ ...
- 倒置数组 Exercise07_12
import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:倒置数组 * */ public class Exercise07_12 ...
- 深度学习的GDB调试命令和经验记录
调试的指令很简单: cd $CAFFE_ROOT, 1. gdb ./build/tools/caffe 2. 设置运行参数 set args train --solver=xxxxsolver.pr ...
- python笔记4-遍历文件夹目录os.walk()
前言 如何遍历查找出某个文件夹内所有的子文件呢?并且找出某个后缀的所有文件 walk功能简介 1.os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. 2.walk()方 ...
- Android内存优化1 了解java内存分配 1
开篇废话 今天我们一起来学习JVM的内存分配,主要目的是为我们Android内存优化打下基础. 一直在想以什么样的方式来呈现这个知识点才能让我们易于理解,最终决定使用方法为:图解+源代码分析. 欢迎访 ...