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长了一张包子脸.他特别喜欢吃糖果.如今他手头有若干种糖果,每种糖果有个口味值,每种糖果有无数多个.然后娄童鞋也很喜欢吃糖果.他的口味特别广泛 ...
随机推荐
- SpringCloud多模块整理
1.项目架构 —— project 父项目 —— client 子项目(客户端) 对外暴露的接口 —————— pom.xml 子项目的pom文件 ...
- 《springcloud 五》springcloud stream
什么是消息驱动? SpringCloud Stream消息驱动可以简化开发人员对消息中间件的使用复杂度,让系统开发人员更多尽力专注与核心业务逻辑的开发.SpringCloud Stream基于Spri ...
- CSS grid layout demo 网格布局实例
直接 上代码,里面我加注释,相当的简单, 也可以去我的github上直接下载代码,顺手给个星:https://github.com/yurizhang/micro-finance-admin-syst ...
- JAVA基础之字节流与字符流
个人理解: IO流就是将数据进行操作的方式,因为编码的不同,所以对文件的操作就产生两种.最好用字节流,为了方便看汉字等,(已经确定文字的话)可以使用字符流.每个流派也就分为输入和输出,这样就可以产生复 ...
- dubbo rest返回值异常Incompatible types: declared root type
2018-08-28 17:26:02,208 [http-bio-9090-exec-1][][][][][] ERROR com.wjs.member.plugin.intercepter.Ser ...
- Home is where your heart is
Home is where your heart is.心之所在即为家.
- zTree使用随笔
最近开发过程中,需要写一个公司人员组织架构的树状图,后来选用了依赖jQuery的zTree插件来实现,主要是该插件功能齐全,性能稳定,个性化编辑方便,遂选用了这个插件.我记录了一下根据自身需求定制化修 ...
- 如何删除 CentOS 6 更新后产生的多余的内核?
第一种方法:通过命令的方式解决多余的内核 1.首先查看当前内核的版本号: [root@jxatei ~]# uname -a Linux jxatei.server2.6.32-573.1.1.el ...
- 一键部署Moodle开源课程管理系统
产品详情 产品介绍Moodle https://moodle.org/ 是一个开源及自由的电子学习软件平台,亦称为课程管理系统.学习管理系统或虚拟学习环境.Moodle 特色异于其他商业线上教学平台, ...
- JAVA图形界面常用知识点总会《代码分析》
1. package CLASS16.bin.com.GridLayout; import javax.swing.ImageIcon;import javax.swing.JFrame;import ...