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 ...
随机推荐
- [转][IIS]发布网站,提示用户 'IIS APPPOOL\***' 登录失败。
链接:http://www.cnblogs.com/tianguook/p/3881075.html 用户 'IIS APPPOOL\DefaultAppPool' 登录失败. 我在windows8中 ...
- Fom同时控制每一行不同的状态
代码:app_item_property.set_property('HEADER.MATTER_CODE', alterable,property_off); 实现效果: ...
- HTML第四天学习笔记
今天老师教了下无序列表和有序列表,虽然并没有,同时做了个随堂练习: <html> <head> <title>随堂练习00</title> <me ...
- Firefox插件一键切换兼容IE
转载:http://mozilla.com.cn/thread-42137-1-1.html 让火狐兼容IE的双核扩展,一键切换至IE内核,网银支付无忧愁.支持Adblock plus和FireGes ...
- pic/at89c2051 programmer
http://dangerousprototypes.com/forum/viewtopic.php?t=170 It looks like the PICKIT2 uses a small boos ...
- Android中显示网页的多种方式
在android中显示页面主要有两种方式,一种是在Activity里面直接显示网页,另一种是调用浏览器显示网页.方式不同,使用的方法也不同,下面我们分别讲解. 一.在Activity里面直接显示网页 ...
- Android学习之路
Android基础 整理下个人认为新手们必须要掌握的知识点,顺便也会附带相应觉得不错的讲解博客地址. 两分钟彻底让你明白Android Activity生命周期(图文)! Activity实际开发中使 ...
- FindMe
https://github.com/hongdong/FindMe_Android https://github.com/hongdong/FindMe_Server https://github. ...
- C# Redis分布式缓存
C# Redis实战(七) 七.修改数据 在上一篇 C# Redis实战(六)中介绍了如何查询Redis中数据,本篇将介绍如何修改Redis中相关数据.大家都知道Redis是key-value型存储系 ...
- dsPIC33EP 高速PWM模块初始化设置及应用
//文件 p33pwm6.h #ifndef _P33PWM6_H_ #define _P33PWM6_H_ //#include "p33pwm6.h" #define FSYN ...