Flying to the Mars

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

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
 
Author
PPF@JLU
 
题意:
速度大小递增的分在一个集合里,即速度大小不同的才能在一个集合里,问最少分几个集合。
代码:
 //本质就是找最多有多少相同的数字。处理前导零,还有这个数就是0的情况;又糊涂了,竟然把每个经过的点都加了一,只加最后一个才能标记一个数啊!!!
#include<iostream>
#include<cstdio>
#include<cstring>
#include<malloc.h>
using namespace std;
struct Trie
{
int v;
Trie *next[];
};
Trie *root;
void init()
{
root=new Trie;
for(int i=;i<;i++)
root->next[i]=NULL;
root->v=;
}
int Tinsert(char s[])
{
int len=strlen(s),j=;
Trie *p=root,*q;
for(int i=;i<len;i++)
{
if(s[i]!=''||i==len-)
{
j=i;
break;
}
}
for(int i=j;i<len;i++)
{
int id=s[i]-'';
if(p->next[id]==NULL)
{
q=new Trie;
q->v=;
for(int i=;i<;i++)
q->next[i]=NULL;
p->next[id]=q;
}
p=p->next[id];
}
p->v++;
return p->v;
}
void Tdelete(Trie *t)
{
if(t==NULL)
return;
for(int i=;i<;i++)
if(t->next[i]!=NULL)
Tdelete(t->next[i]);
free(t);
}
int main()
{
int n;
char ch[];
while(scanf("%d",&n)!=EOF)
{
init();
int ans=;
for(int i=;i<n;i++)
{
scanf("%s",ch);
int tem=Tinsert(ch);
if(tem>ans) ans=tem;
}
printf("%d\n",ans);
Tdelete(root);
}
return ;
}

*HDU1800字典树的更多相关文章

  1. HDU1800 字典树写法

    题意:高级魔法师可以教低级魔法师 魔法扫把技能,同时教会了的低级魔法师又可以教比他更低级是,是传递的关系 同时如果教会了的话,他们可以同时坐一个扫把 问最少需要多少个扫把 思路:就是判断相同的数字最多 ...

  2. 【字符串算法】字典树(Trie树)

    什么是字典树 基本概念 字典树,又称为单词查找树或Tire树,是一种树形结构,它是一种哈希树的变种,用于存储字符串及其相关信息. 基本性质 1.根节点不包含字符,除根节点外的每一个子节点都包含一个字符 ...

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

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

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

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

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

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

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

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

  7. 山东第一届省赛1001 Phone Number(字典树)

    Phone Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 We know that if a phone numb ...

  8. 字典树 - A Poet Computer

    The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems ...

  9. trie字典树详解及应用

    原文链接    http://www.cnblogs.com/freewater/archive/2012/09/11/2680480.html Trie树详解及其应用   一.知识简介        ...

随机推荐

  1. ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了(转载)

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var mysql 启动不了   ps -A | gr ...

  2. MSYS2的源配置

    关于MSYS2的文章可以参考下面的链接,笔者不多赘述: msys2安装笔记 MSYS2 + MinGW-w64 + Git + gVim 环境配置 msys2环境搭建 msys2安装g++: pacm ...

  3. DbHelper为什么要用Using?

    我们分析一下DbHelper做什么事情,大家都知道它用于数据库的连接操作,这里的数据库连接会创建非托管资源,c#的垃圾回收机制不会对它处理,需要实现IDisposable接口手动释放.   手动释放的 ...

  4. Codeforces#262_1002

    Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 2 ...

  5. 利用Shodan和Censys进行信息侦查

    在渗透测试的初始阶段,Shodan.Censys等在线资源可以作为一个起点来识别目标机构的技术痕迹.本文中就以二者提供的Python API为例,举例介绍如何使用它们进行渗透测试初期的信息侦查. Sh ...

  6. java线程与缓存

    如果在你的服务中用了一些第三方的服务,最好使用缓存配合线程的方式去访问第三方的服务,以免引发线程安全问题,因为第三方的服务你不知道人家对于多线程是如何处理的,所以我们要在自己的程序中做一些线程安全的处 ...

  7. mongodb的查询语句学习摘要

    看了些资料,对应只需要知道怎么查询和使用mongodb的我来说,这些足够啦. 左边是mongodb查询语句,右边是sql语句.对照着用,挺方便. db.users.find() select * fr ...

  8. ul、li分列显示

    目的很简单:有一个 ul>li 列表,默认为单列显示,把它变为两列显示. 方法1,使用DIV+CSS代码: <style type="text/css"> .my ...

  9. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  10. 问题:QXcbConnection: Could not connect to display

    Wkhtmltopdf 失败 (错误代码: -6). 消息: The switch --header-spacing, is not support using unpatched qt, and w ...