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++笔记3
一基本语法: 1.1 字符串:支持标准C的 const char* pch=0/"";//不指向任何对象和指向空字符串.C++提供的string类可提供字符串的所有操作,最好是融合 ...
- AD中添加中文字符丝印的方法:
一 一般中文丝印: 用快捷键L打开层管理,在View options中勾选convert special 选项: 用快捷键P,S文本中输入你要的汉字,选中ture type,在select ture ...
- SPRING代理模式
1.静态代理 主题对象:Student public interface Student { public String add(); } 目标对象:RealStudent public class ...
- MariaDB 实现主从复制
實驗目的: MariaDB為MySQL的一個分支,其完全開源.無版權之虞且操作上與 MySQL 一脈相承,實際應用中非常廣泛,軟件本身很小,安裝容易,使用簡單. 但其也有缺點,指令行方式操作,無原生G ...
- PHPStorm2017.1.3永久激活方法之本地破解激活
是时候升级你的phpstorm了,咱们马上行动! 下载 1.phpstorm https://www.jetbrains.com/phpstorm/download/ 2.破解包 破解补丁无需使用注册 ...
- JavaScript笔记6-数组新方法
七.ECMAScript5关于数组的新方法 1.forEach():遍历数组,并为每个元素调用传入的函数; 举例: var a = [1,2,3]; var sum = 0; //传一个 ...
- js操作文档对象的节点
好吧,为了能让大家不至于睡着,我们先回顾先前面的东东吧~ 1.首先我们写了javaScriput的是一门弱类型的解释性的脚本语言:弱类型:我们的变量不用申明其具体的数据类型,在使用的时候浏览器根据其存 ...
- (五)SpringMVC之使用Kaptcha实现验证码功能
一.什么是Kaptcha Kaptcha是Google开发的用于自动生成验证码的插件. 二.怎么导入Kaptcha ① 如果没有用Maven管理工具的话就直接导入包(可以直接下载:pau8) http ...
- 监控服务端口状态python脚本
#!/usr/bin/python import socket,os,time data={ 8080:"tomcat9", 18080:"tomcat_hjgdmj&q ...
- CocoaPods在OS X Yosemite上突然不能用了的解决办法
最近开发的时候发现自己的CocoaPods不能使用了! 根据报的错误上网搜寻answer,于是搜到了解决办法 在 OS X Yosemite 报这样的错: [MT] DVTAssertions: AS ...