题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1251

node *head=(node*)malloc(sizeof(node));
for(int i=0; i<26; i++)
{
head->next[i] = NULL;
head->sum = 0;
}
可以改成node *head=new node();
要用c++提交才对,不然G++就内存超限了-_-
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std; struct node
{
int sum;
node *next[];
}; void BuildLibTree(node *head, char s[])
{
node *p = head,*q; for(int i=; s[i]; i++)
{
int k = s[i] - 'a';
if(p->next[k] == NULL)
{
q=(node*)malloc(sizeof(node));
for(int j=; j<; j++)
{
q->next[j] = NULL;
q->sum = ;
}
p->next[k] = q;
}
p = p->next[k];
p->sum++;
}
}
int Query(node *head, char s[])
{
node *p = head;
for(int i=; s[i]; i++)
{
int k = s[i]-'a';
if(p->next[k] == NULL)
return ;
p = p->next[k];
}
return p->sum;
}
int main()
{
char s[];
node *head=(node*)malloc(sizeof(node));
for(int i=; i<; i++)
{
head->next[i] = NULL;
head->sum = ;
}
while(gets(s),s[])
BuildLibTree(head, s); while(scanf("%s",s)!=EOF)
printf("%d\n", Query(head, s));
return ;
}

统计难题---hdu1251字典树模板的更多相关文章

  1. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

  2. HDU1251 统计难题 (字典树模板)题解

    思路:模板题,贴个模板 代码: #include<cstdio> #include<cstring> #include<cstdlib> #include<q ...

  3. HDU 1251 统计难题 (字典树)(查询是否为前缀)

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

  4. HDU 1251 统计难题(字典树入门模板题 很重要)

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

  5. hdu 1251 统计难题(字典树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  6. HDU 1251 统计难题 (Trie树模板题)

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

  7. hdu 1251:统计难题(字典树,经典题)

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

  8. [ACM] hdu 1251 统计难题 (字典树)

    统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...

  9. HDU 1251 统计难题(字典树 裸题 链表做法)

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

随机推荐

  1. System.exit(0)会跳过finally块的执行

    public class test { public static void main(String[] args) { try { System.exit(0); System.out.printl ...

  2. 【代码审计】CLTPHP_v5.5.3 前台任意文件上传漏洞

    0x00 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chichu/ ...

  3. Selenium 动作链

    Selenium 模拟浏览器操作,有一些操作,它们没有特定的执行对象,比如鼠标拖曳.键盘按键等,这些动作用另一种方式来执行,那就是动作链 更多动作链参考官网:https://selenium-pyth ...

  4. 层叠样式表css的优先级

    优先级1:外部<内部<行内优先级2:标签选择器<类选择器<ID选择器

  5. WP8.1学习系列(第二章)——Toast通知

    Toast 通知概述(Windows 运行时应用) 你的应用要想通过 Toast 通知通信,必须在应用的清单文件中声明它支持 Toast.Toast 通知可包含文本,并且 Windows 上的 Toa ...

  6. jquery.sparkline.js简介

    jQuery线状图插件Sparkline 官网地址:http://omnipotent.net/jquery.sparkline/ 文档地址:http://omnipotent.net/jquery. ...

  7. spring-data-redis的事务操作深度解析--原来客户端库还可以攒够了事务命令再发?

    一.官方文档 简单介绍下redis的几个事务命令: redis事务四大指令: MULTI.EXEC.DISCARD.WATCH. 这四个指令构成了redis事务处理的基础. 1.MULTI用来组装一个 ...

  8. mysql架构图

    整体架构图 访问控制图

  9. cocos2d-x学习之旅(五):1.5 使用eclipse编译cocos2d-x示例项目,创建cocos2d-x android项目并部署到真机

    今天将cocos2d-x的示例项目tests编译到android真机运行,以及如何创建cocos2d-x的android项目. 打开cocos2d-x的tests项目,路径为:D:\cocos2d-x ...

  10. 【CF700E】Cool Slogans 后缀自动机+线段树合并

    [CF700E]Cool Slogans 题意:给你一个字符串S,求一个最长的字符串序列$s_1,s_2,...,s_k$,满足$\forall s_i$是S的子串,且$s_i$在$s_{i-1}$里 ...