hdu 1251 统计难题(字典树)
统计难题
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)
Total Submission(s): 22291 Accepted Submission(s): 9424
注意:本题仅仅有一组測试数据,处理到文件结束.
banana
band
bee
absolute
acm ba
b
band
abc
2
3
1
0
pid=1298" target="_blank" style="color:rgb(26,92,200); text-decoration:none">1298
1800pid=2846" target="_blank" style="color:rgb(26,92,200); text-decoration:none">2846
题解:建一颗字典树,然后查询出现的次数即可了。
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<cstring>
#define N 10010 using namespace std; int n;
char s[N]; typedef struct tire {
int num;
struct tire *net[26];
}*Tire; void Init(Tire &p) {
p=(Tire)malloc(sizeof(tire));
p->num=0;
for(int i=0; i<26; i++) {
p->net[i]=NULL;
}
} void CreatTire(Tire &p,char s[]) {
int i=0;
Tire q=p;
while(s[i]) {
int nx=s[i]-'a';
if(q->net[nx]==NULL) {
Init(q->net[nx]);
q->net[nx]->num=1;
} else {
q->net[nx]->num++;
}
q=q->net[nx];
i++;
}
} int Serch(Tire p,char s[]) {
int i=0;
Tire q=p;
while(s[i]) {
int nx=s[i]-'a';
if(q->net[nx]==NULL)return 0;
q=q->net[nx];
i++;
}
return q->num;
} int main() {
//freopen("test.in","r",stdin);
Tire p;
Init(p);
while(gets(s)!=NULL&&s[0]!='\0') {
CreatTire(p,s);
}
while(~scanf("%s",s)) {
printf("%d\n",Serch(p,s));
}
return 0;
}
hdu 1251 统计难题(字典树)的更多相关文章
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己 ...
- hdu 1251 统计难题 字典树第一题。
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- 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 ...
- HDU 1251 统计难题(字典树)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU 1251统计难题 字典树
字典树的应用. 数据结构第一次课的作业竟然就需要用到树了!!!这不科学啊.赶紧来熟悉一下字典树. 空间开销太大T T #include<cstdio> #include<cstrin ...
- hdu -1251 统计难题(字典树水题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 建树之后 查询即可. G++提交 ME不知道为什么,c++就对了. #include <iostre ...
- hdoj 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 思路分析:该问题要求求出以某个字符串为前缀的单词数目,通过使用字典树,在字典树中添加count记 ...
随机推荐
- 消除^M
在Linux和windows之间移动文件时,总是会出现在windows下编辑的文件在Linux打开时每一行都显示一个^M,虽然不影响使用,但是却影响美观,于是就想自己实现个小程序来进行转换. 要实现转 ...
- 推广Facebook技巧
1.创建有吸引力的内容发布多样化的内容,包括图片,状态更新,视频,投票等.可以问你的粉丝一些问题让他们提供答案.这些内容不仅你的粉丝可以看到,它们还将会出现在你粉丝的个人动态栏,所以他们的朋友也是可以 ...
- A protocol error occurred. Change of username or service not allowed: (root,ssh-connection) -> (zoujiaqing,ssh-connection)
SecureCRT ssh 客户端连接失败: The server has disconnected with an error. Server message reads: A protocol ...
- Swift基础--ijkplayer编译
这篇与Swift基本上没有什么关系,只是之后会用到,这次编译是使用Mac编译IOS版本号的.以下是编译流程,最后是整个项目的下载地址.由于下载太慢了. 1.下载源代码 git clone https: ...
- C#和Java的类、继承、重写与多态
面向对象的三大特性是封装.继承.多态,C#和Java都是面向对象的语言所以他们的类.继承.重写与多态有很多共同点,但是实现上也存在一定的区别.其中Java中其实没有虚函数的概念,也可以认为Java的函 ...
- 第二百三十一节,Bootstrap 介绍
Bootstrap 介绍 学习要点: 1.Bootstrap 概述 2.Bootstrap 特点 3.Bootstrap 结构 4.创建第一个页面 5.学习的各项准备 本节课我们主要了解一下 Boos ...
- HashTable类
HashTable类不紧可以像Vector类一样动态的存储一系列的对象,而且对存储的每一个对象(称为值)都安排另一个对象(称为关键字)与它相关联. 用做关键字的类必须覆盖Object.hashCode ...
- bgr to rgb
因为在研究车牌识别算法(plr),遇到了算法 处理的格式问题,可分三个常用格式: 0:rgb 1:bgr 2:yuv422——需要注意的是,这里为啥选yuv422做识别,当然还可选yuv444,最坏打 ...
- 使用c++为node.js扩展模块
官方文档 编写c++代码 // demo.cc #include <node.h> using v8::FunctionCallbackInfo; using v8::Isolate; u ...
- 把資源加载到内存中 BMP 出错
BMP文件放到VS的資源中時,VS會將BMP的文件頭去掉,即BITMAPFILEHEADER,這個結構體去除.所以當加載BMP到內存中時,如果是使用GDI+或是其它解釋庫時,會解析失敗. 所以在讀取B ...