hdu1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 33996 Accepted Submission(s): 12855
注意:本题只有一组测试数据,处理到文件结束.
band
bee
absolute
acm
ba
b
band
abc
3
1
0
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define N 500010
struct node{
int w,next[];
}tire[N];
int n,m,cnt;
char s[];
void build(){
int now=,len=strlen(s);
for(int i=;i<len;i++){
if(!tire[now].next[s[i]-'a'+]) tire[now].next[s[i]-'a'+]=++cnt;
now=tire[now].next[s[i]-'a'+];
tire[now].w++;
}
}
int query(){
int now=,len=strlen(s);
for(int i=;i<len;i++){
if(!tire[now].next[s[i]-'a'+]) return ;
now=tire[now].next[s[i]-'a'+];
}
return tire[now].w;
}
int main(){
while(gets(s)){
if(!strcmp(s,"")) break;
build();
}
while(gets(s)) printf("%d\n",query());
return ;
}
hdu1251的更多相关文章
- hdu1251(字典树)
统计难题(hdu1251) Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Tota ...
- hdu1251+字典树常用模板
这里只简单给出几个常用的字典树的模板,要看具体介绍的请看:传送门 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现) ...
- hdu1251 && hud 1247 (字典树)
hdu1251 题目 这道题,主要是在主函数的输入输出上犹豫了. #include<stdio.h> #include<cstring> #include<iostrea ...
- 3道入门字典树例题,以及模板【HDU1251/HDU1305/HDU1671】
HDU1251:http://acm.hdu.edu.cn/showproblem.php?pid=1251 题目大意:求得以该字符串为前缀的数目,注意输入格式就行了. #include<std ...
- Trie 字典树,hdu1251
参考博客:https://www.cnblogs.com/TheRoadToTheGold/p/6290732.html 字典树就是单词树,顺着一条路径到达终止结点就形成一个单词,该单词的前缀包含在这 ...
- *HDU1251 字典树
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu1251 统计难题
地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=1251 题目: 统计难题 Time Limit: 4000/2000 MS (Java/Othe ...
- hdu1251 统计难题 字典树
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu1251 字典树or map
一道字典树的题,不过看起来用map更为简单 传送门 题意: 给出一堆字符串构成一个字典,求字典里以某字符串为前缀的字符串有几个 思路: 输入字符串时把字符串的前缀全部存进map并标记次数 查询时直接输 ...
- hdu1251在词典里统计前缀出现的个数
banana band bee absolute acm ba b band abc #include<iostream> using namespace std; //数据结构 s ...
随机推荐
- application与cache
每个项目都有一些全局,常用的信息,而这些信息如果在每次使用时都载入,那必将耗费很大的资源,特别是对访问压力大的系统.因此,这个情况中,把这些全局信息放到缓存中是很必要的,放在缓存中可以使得数据能够很快 ...
- C10K problem
什么是C10K问题 1W个客户端连接上一个server,客户不定时的发送请求. I/O策略 软件架构 1.单线程解决多重I/O调用 不要使用阻塞/同步的调用,如果非要这么做,那就采用多进程或者 ...
- Keil AGDI Header File
#ifndef __AGDI__INCED___ #define __AGDI__INCED___ //---Revision History: --------------------------- ...
- Educational Codeforces Round 7 C. Not Equal on a Segment 并查集
C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are ...
- Codeforces Round #340 (Div. 2) E. XOR and Favorite Number 莫队算法
E. XOR and Favorite Number 题目连接: http://www.codeforces.com/contest/617/problem/E Descriptionww.co Bo ...
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/ ...
- 无线网卡的查看与配置——iw,iwconfig,ethtool
摘要:在linux上,我们经常需要把一台笔记本设置成一个共享wifi上网的路由器.如果我们需要把本机配置成一台无线AP,就需要查看网卡的相关信息和进行对应配置.其中iw.iwconfig和ethtoo ...
- [转载]GMT地形数据总结
[转载]GMT地形数据总结 原文地址:GMT地形数据总结作者:Jason 转载:http://seisman.info/gmt-topo-grid-datas.html 目前接触到的地形数 ...
- 使用cwRsync实现windows下文件定时同步【转】
1.参考文献: 使用cwRsync实现windows下文件定时同步(备份) 文件同步工具CwRsync的使用方法及常用命令详解 2.背景: 当前的SCADA架构中,有1台Server,5台FE,还有1 ...
- C++调用C#库简单例程
有些时候,为了使用别人已经写好的C#库文件,我们需要使用C++调用C#库文件: 以下做了一简单的调用工程,步骤如下: 1.准备C#库 (dll文件) 1)创建C#库: 2)编写C#类: ...