http://acm.hust.edu.cn/vjudge/problem/16379

题意:给定多个单词,多次询问符合某前缀的单词有多少个。

题解:tire。数组开了5*10^6才A,不然就RE。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<queue>
using namespace std; char s[];
int num;
struct node{
int son[];
int cnt;
}a[]; void clear(int x)
{
a[x].cnt=;
memset(a[x].son,,sizeof(a[x].son));
} void trie(char *c)
{
int l=strlen(c);
int x=;
for(int i=;i<l;i++)
{
int t=c[i]-'a'+;
if(!a[x].son[t])
{
num++;
clear(num);
a[x].son[t]=num;
}
x=a[x].son[t];
a[x].cnt++;
}
} int find(char *c)
{
int l=strlen(c);
int x=;
for(int i=;i<l;i++)
{
int t=c[i]-'a'+;
if(!a[x].son[t]) return ;
else x=a[x].son[t];
}
return a[x].cnt;
} int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
num=;
clear();
while()
{
// scanf("%s",s);
gets(s);
if(strlen(s)==) break;
trie(s);
}
while(scanf("%s",s)!=EOF)
{
printf("%d\n",find(s));
}
return ;
}

【hdu1251-统计难题】Trie的更多相关文章

  1. HDU1251 统计难题 Trie树

    题目很水,但毕竟是自己第一道的Trie,所以还是发一下吧.Trie的更多的应用慢慢学,AC自动机什么的也慢慢学.... #include<iostream> #include<cst ...

  2. [hdu1251]统计难题(trie模板题)

    题意:返回字典中所有以测试串为前缀的字符串总数. 解题关键:trie模板题,由AC自动机的板子稍加改造而来. #include<cstdio> #include<cstring> ...

  3. HDU1251 统计难题 trie树 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 找前缀数量 裸模板 #include<cstdio> #include<cstr ...

  4. HDU1251统计难题---Trie Tree

    map巧过 #include <stdio.h> #include <string.h> #include <map> #include <string> ...

  5. HDU1251 统计难题(Trie)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  6. hdu1251统计难题(trie)

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others)Total Submi ...

  7. HDU1251 统计难题 【trie树】

    统计难题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131070/65535 K (Java/Others) Total Subm ...

  8. hdu1251 统计难题

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...

  9. hdu 1251 统计难题 trie入门

    统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...

  10. HDU 1251 统计难题(Trie)

    统计难题 [题目链接]统计难题 [题目类型]Trie &题解: Trie的模板题,只不过这题坑点在没给数据范围,改成5e5就可以过了,用的刘汝佳蓝书模板 &代码: #include & ...

随机推荐

  1. PHP批量替换MySql数据库中的数据内容

    <?php //替换数据库内容类 class replace{ public $dbAddress; //数据库地址 public $dbUser; //数据库用户名 public $dbPwd ...

  2. 两个完整的jquery slide多方面滑动效果实例

    实例1,需要引用jquery-ui.js <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu ...

  3. Epplus下的一个将Excel转换成List的范型帮助类

    因为前一段时间公司做项目的时候,用到了Excel导入和导出,然后自己找了个插件Epplus进行操作,自己将当时的一些代码抽离出来写了一个帮助类. 因为帮助类是在Epplus基础之上写的,项目需要引用E ...

  4. 在PXC中重新添加掉线节点

      Preface       When we add a new node into PXC structure,it will estimate the mothed(IST/SST) to tr ...

  5. JQuery UI 日历加时间

    写一个面试时间通知.用jquery ui 具体功能已经可以了,不过样式还没调 一.需要引入的文件,这些可以到官网下载 <link rel="stylesheet" href= ...

  6. Wordpress 设置后台自定义post 排序

    创建新的 Post type时,文章在后台默认使用 Titile 列进行升序排序,但是通常情况下我们需要按日期 Date 进行降序排序, function wpse_81939_post_types_ ...

  7. cpp语言程序设计教程第七章的一道编程题

    题目如下 按下列要求实现一个有关学生成绩的操作. 该类名为Student. (1)每个学生的信息包含有姓名(字符数组)和成绩(int型). (2)共有5个学生,用对象数组表示. (3)计算出5个学生中 ...

  8. 并查集——hdu1213(入门)

    传送门:How Many Tables 模板代入 判断几个连通分支 DFS亦可完成 [并查集] #include <iostream> #include <cstdio> #i ...

  9. Alpha阶段展示

    程序员杀产品经理祭天(SacrificePM)团队 1.团队成员简介和个人博客地址 故事 我们队伍的建立过程稍具戏剧性,大家看我们也颇为奇怪,这么一支8人队伍是怎么诞生的呢?其实我们原本分属三组,而第 ...

  10. 我和C语言程序

    姓名:江超鸿 学号:160809129 爱好:打台球.听音乐 博客地址:https://www.cnblogs.com/jiangchaohong/ C语言:对于c语言程序来说,我是第一次接触,对它的 ...