HDU 1251 统计难题(Trie)
统计难题
【题目链接】统计难题
【题目类型】Trie
&题解:
Trie的模板题,只不过这题坑点在没给数据范围,改成5e5就可以过了,用的刘汝佳蓝书模板
&代码:
#include <cstdio>
#include <bitset>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxNode= 500000 +7,sigmaSize=26;
struct Trie
{
int ch[maxNode][sigmaSize],sz,val[maxNode];
Trie(){sz=1; memset(ch[0],0,sizeof(ch[0])); memset(val,0,sizeof(val));}
int idx(char c){return c-'a';}
void insert(char* s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++){
int c=idx(s[i]);
if(!ch[u][c]){
memset(ch[sz],0,sizeof(ch[sz]));
ch[u][c]=sz++;
}
u=ch[u][c];
val[u]++;
}
}
int query(char* s)
{
int u=0,n=strlen(s);
for(int i=0;i<n;i++){
int c=idx(s[i]);
if(!ch[u][c]){
return 0;
}
u=ch[u][c];
}
return val[u];
}
}tr;
char s[23];
int main()
{
while(1){
gets(s);
int n=strlen(s);
if(n==0) break;
tr.insert(s);
}
while(gets(s)){
printf("%d\n",tr.query(s));
}
return 0;
}
HDU 1251 统计难题(Trie)的更多相关文章
- hdu 1251 统计难题 trie入门
统计难题 Problem Description Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本 ...
- hdu 1251 统计难题(trie树入门)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- HDU - 1251 统计难题(trie树)
Ignatius最近遇到一个难题,老师交给他很多单词(只有小写字母组成,不会有重复的单词出现),现在老师要他统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). Input输入数据的第一部 ...
- HDU 1251 统计难题 (Trie)
pid=1251">统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/ ...
- hdu 1251 统计难题(字典树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) M ...
- HDU 1251 统计难题(Trie模版题)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others) Total Subm ...
- HDU 1251 统计难题 (字符串-Trie树)
统计难题 Problem Description Ignatius近期遇到一个难题,老师交给他非常多单词(仅仅有小写字母组成,不会有反复的单词出现),如今老师要他统计出以某个字符串为前缀的单词数量(单 ...
- hdu 1251:统计难题[【trie树】||【map】
<题目链接> 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131 ...
- hdu 1251 统计难题 (字典树(Trie)<PS:C++提交不得爆内存>)
统计难题Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submis ...
随机推荐
- Lombok安装及使用
为什么要使用Lombok: 虽然一般的IDE(eclipse,Intellij)都有自动生成代码的功能,如:生成setter,getter,toString,equels,hashcode等.但是如果 ...
- 3-idiots hdu4609 母函数+FFT 组合数学题
http://acm.hdu.edu.cn/showproblem.php?pid=4609 题意:1e5个数,求取三个数能形成三角形的概率. 题解(这怎么会是fft入门题QAQ): 概率的算法就是三 ...
- 编译安装spark 1.5.x(Building Spark)
原文连接:http://spark.apache.org/docs/1.5.0/building-spark.html · Building with build/mvn · Building a R ...
- Android 屏蔽Power键 Home键
Android 屏蔽Power键 Home键 标签: androidpower键Home键PhoneWindowManagerframework 2014-04-18 17:22 1557人阅读 评论 ...
- [about remote controller]--mstsc-teamviewer-vnc,nomachine
https://www.jianshu.com/p/c80db368ed8a https://www.nomachine.com/download Ubuntu安装VNC,VNC却无法随系统启动,遂换 ...
- 转:web.xml 配置中classpath: 与classpath*:的区别
原文链接:web.xml 配置中classpath: 与classpath*:的区别 引用自:http://blog.csdn.net/wxwzy738/article/details/1698393 ...
- MonkeyRunner_批处理执行py文件
新建bat文件,使用call调用monkeyrunner执行py脚本 @echo off echo begin testcase001 %time% %date%call monkeyrunner d ...
- HashMap如何解决取Value值为Null
场景: 用HashMap方法时候,取Keys时候自认为敲的肯定是准确无误,然后能得到对应的Values 值. 但写脚本代码时候不好习惯,没事总喜欢敲个空格建,导致取Keys之后多空格. Featur ...
- python pip install 报错TypeError: unsupported operand type(s) for -=: 'Retry' and 'int' Command "python setup.py egg_info" failed with error code 1 in
pip install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl ...
- Java 用HTTP的方式发送JSON报文请求
前言: 项目调用第三方接口时,通常是用socket或者http的通讯方式发送请求:http 为短连接,客户端发送请求都需要服务器端回送响应,请求结束后,主动释放链接.Socket为长连接:通常情况下S ...