hdoj1251-统计难题 【字典树】
http://acm.hdu.edu.cn/showproblem.php?pid=1251
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 19902 Accepted Submission(s): 8720
注意:本题只有一组测试数据,处理到文件结束.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
using namespace std; #define MAX 0x7fffffff struct node{
node* word[];
int n;
node(){
for(int i=;i<;i++) word[i]=NULL;
n=;
}
}*root; void Insert(char* s);
int Find(char* s); int main(){
//freopen("D:\\input.in","r",stdin);
//freopen("D:\\output.out","w",stdout);
char tmp[];
root=new node;
while(gets(tmp),strlen(tmp)){
Insert(tmp);
}
while(gets(tmp)!=NULL){
printf("%d\n",Find(tmp));
}
return ;
}
void Insert(char* s){
int len=strlen(s);
node *current=root,*new_node;
for(int i=;i<len;i++){
if(current->word[s[i]-'a']!=NULL){
current=current->word[s[i]-'a'];
current->n++;
}else{
new_node=new node;
current->word[s[i]-'a']=new_node;
current=current->word[s[i]-'a'];
}
}
}
int Find(char* s){
int len=strlen(s);
node *current=root;
for(int i=;i<len;i++){
if(current->word[s[i]-'a']!=NULL){
current=current->word[s[i]-'a'];
}else{ return ; }
}
return current->n;
}
hdoj1251-统计难题 【字典树】的更多相关文章
- hdoj1251 统计难题 字典树
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu_1251统计难题(字典树Trie)
统计难题 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 Submi ...
- hdu 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU-1251 统计难题,字典树或者map!
统计难题 很久就看过这个题了,但不会~~~不会~~ 题意:给出一张单词表,然后下面有若干查询,每次给出一个单词,问单词表中是否存在以这个单词为前缀的单词,输出数量.本身也是自身的前缀.只有一组数据! ...
- HDU 1251 统计难题 字典树大水题
今天刚看的字典树, 就RE了一发, 字典树原理还是很简单的, 唯一的问题就是不知道一维够不够用, 就开的贼大, 这真的是容易MLE的东西啊, 赶紧去学优化吧. HDU-1251 统计难题 这道题唯一的 ...
- hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
- hdoj 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 思路分析:该问题要求求出以某个字符串为前缀的单词数目,通过使用字典树,在字典树中添加count记 ...
随机推荐
- mac电脑链接安卓手机的方法
https://blog.csdn.net/liubin9043/article/details/78928253/ 我用了个爱莫 不错 http://web.airmore.com
- [转]预编译 ASP.NET 网站
转自:如何:预编译 ASP.NET 网站 Visual Studio 2005 预编译 ASP.NET 网站可缩短用户的初始响应时间,因为页在第一次被请求时无需编译.这对于经常更新的大型网站尤其有 ...
- [转]Windows 注册自定义的协议
[转自] http://blog.sina.com.cn/s/blog_86e4a51c01010nik.html 1.注册应用程序来处理自定义协议 你必须添加一个新的key以及相关的value到HK ...
- gradle使用心得
gradle是语言式构建,和maven配置型还是差别挺大,琢磨了2天 1.在解析setting.gradle之后,开始解析build.gradle之前,这里如果要干些事情(更改build.gradle ...
- 文件系统性能测试--iozone
iozone 一个文件系统性能评测工具,可以测试Read, write, re-read,re-write, read backwards, read strided, fread, fwrite, ...
- 使用 Nmon 监控 Linux 的系统性能
Nmon(得名于 Nigel 的监控器)是IBM的员工 Nigel Griffiths 为 AIX 和 Linux 系统开发的一款计算机性能系统监控工具.Nmon 可以把操作系统的统计数据展示在屏幕上 ...
- sql上下级关系查询
有一张存在上下级关系的function表,parentId表示上级Id,现要查询出上级菜单下的子菜单,每个子菜单显示成以逗号分隔的字符串 表结构如下: create table menu ( id i ...
- 搭建Hive 2.1.1 基于Hadoop 2.6.1 和 Ubuntu 16.0.4 记录
Hadoop Hive Hbase 对应版本 Hive官网下载 我们以Hadoop版本作为参考适配Hive Hbase即可, Hadoop版本是2.6.1 所以可以选择Hive1.2.1以上版 ...
- ORM Nhibernet 框架的 CRUD 操作
Nhibernet 的基本语法: private ISession _session; public ISession Session { set { _session = value; } } pu ...
- python-log-env
logging.basicConfig(format="[%(asctime)s] %(filename)s[line:%(lineno)d] %(levelname)s: %(messag ...