huu 1251
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cstdlib>
#include <deque>
#include <set>
typedef long long ll;
#define lowbit(x) (x&(-x))
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
using namespace std;
const int N=1e6+;
int tree[N][];//26个字母
int num[N];
char s[];
int pos;
void insert(char s[]){
int root=,i;
for(i=;s[i];i++){
int x=s[i]-'a';
if(!tree[root][x]){
tree[root][x]=pos++;
}
root=tree[root][x];
num[root]++;
}
}
int query(char s[]){
int i;
int root=;
for(i=;s[i];i++){
int x=s[i]-'a';
if(!tree[root][x]){
return ;
}
root=tree[root][x];
}
return num[root];
}
int main()
{
pos=;
/*
memset(tree,0,sizeof(tree));
memset(num,0,sizeof(num));
*/
//加上上面的会超内存
while(gets(s)){//不要用scanf
if(s[]==NULL)
break;
insert(s);
}
while(gets(s)){
printf("%d\n",query(s));
}
return ;
}
huu 1251的更多相关文章
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- hduoj 1251 统计难题
http://acm.hdu.edu.cn/showproblem.php?pid=1251 统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hdu 1251 统计难题 (字典树入门题)
/******************************************************* 题目: 统计难题 (hdu 1251) 链接: http://acm.hdu.edu. ...
- BZOJ 1251: 序列终结者
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MB Submit: 3773 Solved: 1579 [Submit][Status][Dis ...
- ural 1251. Cemetery Manager
1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- Poj(1251),Prim字符的最小生成树
题目链接:http://poj.org/problem?id=1251 字符用%s好了,方便一点. #include <stdio.h> #include <string.h> ...
- njoj 1251 zlly长了一张包子脸
njoj 1251 zlly长了一张包子脸 题意: zlly长了一张包子脸.他特别喜欢吃糖果.如今他手头有若干种糖果,每种糖果有个口味值,每种糖果有无数多个.然后娄童鞋也很喜欢吃糖果.他的口味特别广泛 ...
随机推荐
- C# 加密、解密函数
#region ========加密======== /// <summary> /// 加密 /// </summary> /// <param name=" ...
- 初学Android,创建,启动,停止Service(五十八)
Service跟Windows系统里的服务概念差不多,都在后台执行,它跟Activity的最大区别就是,它是无界面的 开发Service与开发Activity的步骤类似 1.定义一个继承Service ...
- Node.js 历史
Node.js 是在 2009年5月份创建的,是属于典型的 Git 和 GitHub 时代最初孕育的项目.另外需要先说明一点,那就是回顾 Node.js 的历史,并不是仅仅为了给大家回味,而是想找到在 ...
- 使用jQuery发送ajax
我们先看一下js的原生ajax 直接进入代码,我们先准备好servlet,之后不会改动,所以先看一下. package cn.curry.servlet; import com.alibaba.fas ...
- Electron 入门文档
https://www.kancloud.cn/wizardforcel/electron-doc/137765 https://segmentfault.com/a/1190000006207600 ...
- PHP的加解密:如何安装ioncube扩展?
一.下载loader-wizard.php(支持php5.3.php5.4.php5.5.php5.6版本) ioncube提供了一个安装的向导程序,可以非常方便的帮助检测php的运行环境,自动给出提 ...
- Java中方法的继承以及父类未被子类覆盖的方法调用的问题
在看java继承这一块的时候发现了一个问题,即父类未被子类覆盖的方法是如何调用的? 是子类拥有了父类的该方法只是没有显示表示,还是子类调用了父类的该方法. 为此做了一下验证 代码如下: public ...
- 一款新型的EASY饼图数据统计Jquery插件
http://www.oschina.net/code/snippet_197014_12865 http://www.cnblogs.com/ada-zheng/p/3760947.html - ...
- GPnP profile内容
<?xml version="1.0" encoding="UTF-8"?> <gpnp:GPnP-Profile Version=&quo ...
- MVC的验证码
后台: /// <summary> /// 创建验证码的图片 /// </summary> /// <param name="validateCode" ...