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

建树之后 查询即可.

G++提交 ME不知道为什么,c++就对了。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue>
#include <deque>
//#pragma comment(linker, "/STACK:102400000,102400000")
#define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define INF 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 310
#define maxv 50010
#define mod 1000000000
using namespace std; typedef struct node
{
int count;
struct node *next[];
}*tree; void insert(tree p,char *s)
{
tree h=p;
int l=strlen(s);
for(int i=;i<l;i++)
{
int index=s[i]-'a';
if(h->next[index]!=NULL)
{
h=h->next[index];
h->count++;
}
else
{
tree tem=(tree)calloc(,sizeof(node));
tem->count=;
h->next[index]=tem;
h=tem;
}
}
} int find(tree p,char *s)
{
tree h=p;
int l=strlen(s);
for(int i=;i<l;i++)
{
int index=s[i]-'a';
if(h->next[index]==NULL) return ;
h=h->next[index];
}
return h->count;
}
int main()
{
//Read();
char s[];
tree head=(tree)calloc(,sizeof(node));
while(gets(s)&&s[])
{
insert(head,s);
//printf("%s\n",s);
}
//printf("1\n");
while(~scanf("%s",s))
{
printf("%d\n",find(head,s));
}
free(head);
return ;
}

hdu -1251 统计难题(字典树水题)的更多相关文章

  1. hdu 1251 统计难题 (字典树入门题)

    /******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...

  2. hdu 1251 统计难题 字典树第一题。

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

  3. HDU 1251 统计难题 字典树大水题

    今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...

  4. HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)

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

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

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

  6. hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)

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

  7. HDU 1251 统计难题(字典树)

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

  8. HDU 1251统计难题 字典树

    字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...

  9. HDU 1251 统计难题(Trie模版题)

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

随机推荐

  1. Android开发学习——Volley框架

    转载至: http://blog.csdn.net/guolin_blog/article/details/17482095 一些概念性的东西 大家进入上边链接理解,我贴一下 具体的实现代码: pub ...

  2. 调度工具taskctl跨调度服务依赖实现

    调度工具taskctl虽然支持分布式调度,但是有的时候,不同重要程度的调度服务还是要区分开来,在区分开后,不同调度服务之间怎么实现依赖啦, 其实有很多方式,比如写文件,写数据库之类的,这些都可以根据用 ...

  3. 数据字典Dictionary存放键值对

    1.     方法思路: 使用数据字典[Dictionary<string, string>],声明一个list集合,将“XML子节点名称”.“节点值”以键[节点名称]值[节点值]对的形式 ...

  4. 深度神经网络简述与Capsule介绍

    本人最近初学Hinton大神的论文<Dynamic Routing Between Capsules >,对深度神经网络的内容进行了简要总结,将观看“从传统神经网络的角度解读Capsule ...

  5. 飞思卡尔开发板-迅为IMX6开兼容单核 双核 四核Plus开发板

    飞思卡尔开发硬件接口介绍: 核心板参数 尺寸:51mm*61mm CPU:Freescale Cortex-A9 四核 i.MX6Q,主频 1.2 GHz 内存:2GB DDR3 存储:16GB EM ...

  6. uiviewcontroller顶级布局控制

    @available(iOS 7.0, *) open var edgesForExtendedLayout: UIRectEdge // Defaults to UIRectEdgeAll @ava ...

  7. C 语言指针 5 分钟教程

    指针.引用和取值 什么是指针?什么是内存地址?什么叫做指针的取值?指针是一个存储计算机内存地址的变量.在这份教程里“引用”表示计算机内存地址.从指针指向的内存读取数据称作指针的取值.指针可以指向某些具 ...

  8. Sql Server cross apply和outer apply

    with result as( select t.str from( ' str union all ' str union all ' str union all ' str union all ' ...

  9. JavaSE-21 字符编码简介

    ASCII ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统,主要用于显示现代英 ...

  10. OpenGL C#绘图环境配置

    OpenGL C#绘图环境配置   OpenGL简介 OpenGL作为一种图形学编程接口已经非常流行, 虽然在大型游戏方面DirectX有一定的市场占有率, 但由于OpenGL的开放性,可移植性等优点 ...