hdu 1251 统计难题 前缀出现次数
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 65094 Accepted Submission(s): 22446
注意:本题只有一组测试数据,处理到文件结束.
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int tree[][],sum[];
char s[];
int num=;
void insert()
{
int root=,len,id;
len=strlen(s);
for(int i=;i<len;i++)
{
id=s[i]-'a';
if(tree[root][id]==)//字母之前没有出现过,插入一个新位置
tree[root][id]=++num;
sum[tree[root][id]]++;//保存前缀出现的次数
root=tree[root][id];//顺着字典树往下走
}
}
int search()
{
int root=,id,len;
len=strlen(s);
for(int i=;i<len;i++)
{
id=s[i]-'a';
if(tree[root][id]==)
return ;//字典树中没有这个前缀
root=tree[root][id];
}
return sum[root];
}
int main()
{
while(gets(s)&&strlen(s)!=)
{
insert();
}
while(cin>>s&&strlen(s)!=)
{
cout<<search()<<endl;
}
return ;
}
hdu 1251 统计难题 前缀出现次数的更多相关文章
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- HDU 1251 统计难题 (Trie)
pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/ ...
- HDU 1251 统计难题 (字典树)(查询是否为前缀)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- [ACM] hdu 1251 统计难题 (字典树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- HDU 1251 统计难题(字典树入门模板题 很重要)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU 1251统计难题
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- Android数据库高手秘籍(二):创建表和LitePal的基本用法
原文:http://blog.jobbole.com/77157/ 上一篇文章中我们学习了一些Android数据库相关的基础知识,和几个颇为有用的SQLite命令,都是直接在命令行操作的.但是我们都知 ...
- jquery源码部分分析
1.整体架构和如何辨别浏览器端和node端 自执行函数,判断在什么端,如果在浏览器端就执行factory函数 //(function(){a,b})(a,b) //jq大架构,闭包,自执行函数,传入函 ...
- CentOS 下 安装 nginx 执行配置命令 ./configure 报错
CentOS 下 安装 nginx 执行配置命令 ./configure --prefix=/opt/nginx --sbin-path=/usr/bin/nginx 时提示以下错误: checkin ...
- Day3-C-Radar Installation POJ1328
Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. ...
- Time Series_2_Multivariate_TBC!!!!
1. Cointegration 2. Vector Autoregressive Model 3. Impulse-response Function 4. Volatility Modeling ...
- PHP如何查找一列有序数组是否包含某值(二分查找)
问题:对于一列有序数组,如何判断给出的一个值,该值是否存在于数组. 思路:判断是否存在,最简单是,直接循环该数组,对每一个值进行比较.但是对于有序数组来说,这样写就完全没有利用好“有序”这一特点. 所 ...
- redis缓存穿透,缓存击穿,缓存雪崩问题
缓存穿透 缓存查询一般都是通过key去查找value,如果不存在对应的value,就要去数据库中查找.如果这个key对应的value是一定不存在的,并且对该key并发请求很大,就会对数据库产生很大的压 ...
- elk基本配置
https://www.cnblogs.com/zsl-find/articles/10730458.html https://www.cnblogs.com/mylovelulu/p/1053000 ...
- 扩展新函数给window
page.exposeFunction(name, puppeteerFunction) name <string> Name of the function on the window ...
- call 和 apply 用法
ECMAScript规范中,所有函数都包含这两个方法,并且两个方法的使用基本一致,都是用于改变函数的作用域,即改变函数体内 this 指向.不同的是 call 方法的第二个参数可以接收任意个参数,以逗 ...