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记 ...
随机推荐
- Ubuntu14.04配置jdk1.8.0_25,可切换版本
下载jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 解压: sudo m ...
- 【Codeforces】CF 467 C George and Job(dp)
题目 传送门:QWQ 分析 dp基础题. $ dp[i][j] $表示前i个数分成j组的最大和. 转移显然. 吐槽:做cf题全靠洛谷翻译苟活. 代码 #include <bits/stdc++. ...
- 伯克利、OpenAI等提出基于模型的元策略优化强化学习
基于模型的强化学习方法数据效率高,前景可观.本文提出了一种基于模型的元策略强化学习方法,实践证明,该方法比以前基于模型的方法更能够应对模型缺陷,还能取得与无模型方法相近的性能. 引言 强化学习领域近期 ...
- 微软&中科大提出新型自动神经架构设计方法NAO
近期,来自微软和中国科学技术大学的刘铁岩等人发表论文,介绍了一种新型自动神经架构设计方法 NAO,该方法由三个部分组成:编码器.预测器和解码器.实验证明,该方法所发现的架构在 CIFAR-10 上的图 ...
- 搭建Discuz论坛
准备 LAMP 环境 LAMP 是 Linux.Apache.MySQL 和 PHP 的缩写,是 Discuz 论坛系统依赖的基础运行环境.我们先来准备 LAMP 环境 安装 MySQL 使用 yum ...
- 详解Tomcat配置及使用
2018年06月27日 23:42:34 尘埃丶落定 阅读数:2351 版权声明:本文为博主原创文章,转载请附上作者与出处. https://blog.csdn.net/longyin0528/ ...
- Sklearn与特征工程
Scikit-learn与特征工程 “数据决定了机器学习的上限,而算法只是尽可能逼近这个上限”,这句话很好的阐述了数据在机器学习中的重要性.大部分直接拿过来的数据都是特征不明显的.没有经过处理的或者说 ...
- 位运算骚操作 Part 1
▶ 原文标题<Bit Twiddling Hacks>,地址:https://graphics.stanford.edu/~seander/bithacks.html ▶ 额外参考资料:h ...
- spring security 配置xml 参考
https://blog.csdn.net/zsq520520/article/details/77880491
- thymeleaf的使用
1.导包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...