HDU 1251 统计难题【字典树】
题意:中文题--跟着模板敲的--第一棵字典树--@_@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef struct node
{
int cnt;
struct node *next[];
} Trie;
Trie *create()
{
Trie *p=(Trie *)(malloc)(sizeof(Trie));
p->cnt=;
for(int i=;i<;i++) p->next[i]=NULL;
return p;
} void insert(Trie *p,char *str)
{
int i=;
while(str[i])
{
int idx=str[i]-'a';
if(p->next[idx]) p->next[idx]->cnt++;
else p->next[idx]=create();
p=p->next[idx];
i++;
}
}
int search(Trie *p,char *str)
{
int len=strlen(str);
for(int i=;i<len;i++)
{
int idx=str[i]-'a';
p=p->next[idx];
if(p==NULL) return ;
}
return p->cnt;
} int main()
{
Trie *p=create();
char str[];
while(gets(str)&&str[])
insert(p,str);
while(scanf("%s",str)!=EOF)
printf("%d\n",search(p,str));
}
HDU 1251 统计难题【字典树】的更多相关文章
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu 1251 统计难题 字典树第一题。
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU 1251 统计难题 字典树大水题
今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...
- hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
- HDU 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 1251统计难题 字典树
字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...
- hdu -1251 统计难题(字典树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...
- hdoj 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 思路分析:该问题要求求出以某个字符串为前缀的单词数目,通过使用字典树,在字典树中添加count记 ...
随机推荐
- javascript设计模式--中介者模式(Mediator)
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ 2041
#include <iostream> #include <string> #include <algorithm> using namespace std; st ...
- Activity学习(三)——跳转传值
Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据. Intent是Android一个很重要的类.Intent直译是“意图”,什么是意图呢?比如你想从这个 ...
- 错误 1 无法嵌入互操作类型“Microsoft.Office.Interop.Excel.ApplicationClass”。请改用适用的接口
http://www.cnblogs.com/waitingfor/archive/2011/12/19/2293469.html
- poj 2480 Longge's problem 积性函数
思路:首先给出几个结论: 1.gcd(a,b)是积性函数: 2.积性函数的和仍然是积性函数: 3.phi(a^b)=a^b-a^(b-1); 记 f(n)=∑gcd(i,n),n=p1^e1*p2^e ...
- poj 1733(带权并查集+离散化)
题目链接:http://poj.org/problem?id=1733 思路:这题一看就想到要用并查集做了,不过一看数据这么大,感觉有点棘手,其实,我们仔细一想可以发现,我们需要记录的是出现过的节点到 ...
- AngularJS学习笔记1——什么是AngularJS?
Angular JS是一个由Google维护的开源的Javascript框架,主要作者为: Misko Hevery(angular JS之父, Sr. Computer Scientist at G ...
- Visual Studio 2010 快捷键
Visual Studio 2010 快捷键: CTRL + SHIFT + B 生成解决方案CTRL + F7 生成编译CTRL + O 打开文件CTRL + SHIFT + O 打开项目CTRL ...
- iOS 开发--添加工程
文/Bison(简书作者)原文链接:http://www.jianshu.com/p/dd71e15df5d0著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 第一部分,配置项目 在此只 ...
- 新Android工程src和layout文件夹为空
问题:SDK和ADT版本冲突 解决方案: 1.菜单->Help->Install New Software.. 2.在work with放入地址:http://dl-ssl.google ...