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. html 相对定位 绝对 定位 css + div

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 0 Transitional//EN""http://www.worg/TR/xh ...

  2. ARC(Automatic Reference Counting )技术概述

    此文章由Tom翻译,首发于csdn的blog 转自:http://blog.csdn.net/nicktang/article/details/6792972 Automatic Reference ...

  3. 手动将Excel数据导入SQL

    1. 右键点击数据库名称,Tasks --> Import Data... 2. Choose Data Source:MicroSoft Excel,选择Excel文件和Excel版本.Exc ...

  4. Vuex/Vue 练手项目 在线汇率转换器

    详情请点击: https://zhuanlan.zhihu.com/p/33362758

  5. java web 学习笔记 - 表达式语言

    1.表达式语言简介 主要为了简化mvc中 jsp的代码量,方便进行属性的输出.还可以避免进行属性为空等的判断,表达式默认将null设置为"". 表达式语言的一个最大的好处就是,只需 ...

  6. libevent学习之网络通信

    服务器端要实现网络通信,肯定会用到socket等函数,这几个函数应该没什么问题.libevent默认情况下是单线程的,可以配置成多线程,每个线程有一个event_base,对应一个struct eve ...

  7. Python3.0 调用HTMLTestRunner生成的报告中不能显示用例中print函数的输出

    官方原生的HTMLTestRunner.py支持python2.0版本,python3.0版本的使用需要做一些修改: Python3调用HTMLTestRunner执行用例生成测试报告中,不能正常显示 ...

  8. 微信小程序图片上传java后台(前后端代码)

    小程序代码 upload:function(e){ var that = this; wx.showActionSheet({ itemList: ['从相册选择','拍照'], itemColor: ...

  9. 瀑布流布局js

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  10. MFC定时器的使用

    巧妙地使用定时器能达到意想不到的效果,写界面的时候能实现渐变,也能帮助多线程控制等我们知道,在VC的MFC中,已经为我们封装好了很多全面和强大的函数集,所以在MFC编程时,巧妙地调用MFC函数库可以为 ...