hdu 2846 Repository
http://acm.hdu.edu.cn/showproblem.php?pid=2846
Repository
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2720 Accepted Submission(s): 1060
#include<stdio.h>
#include<iostream>
#include<string.h> using namespace std; struct node
{
int count;
int value;
node *next[];
node()
{
for(int i=;i<;i++)
next[i]=;
count=;
value=;
}
}; void insert(node *&root,char *s,int num)
{
int i=,t=;
node *p=root;
if(!p)
{
p=new node();
root=p;
}
while(s[i])
{
t=s[i]-'a';
if(!p->next[t])
p->next[t]=new node();
p=p->next[t];
if(p->value!=num)
{
p->count++;
p->value=num;
}
// printf("%d\n",p->value);
i++;
}
} int find(node *root,char *s)
{
int i=,t=,ans;
node *p=root;
if(!p)
return ;
while(s[i])
{
t=s[i]-'a';
if(!p->next[t])
return ;
p=p->next[t];
ans=p->count;
i++;
}
return ans;
} int main()
{
int T;
scanf("%d",&T);
char str[];
node *root=NULL;
while(T--)
{
scanf("%s",str);
for(int i=;i<strlen(str);i++)
insert(root,str+i,T+);
}
int Q;
scanf("%d",&Q);
while(Q--)
{
scanf("%s",str);
printf("%d\n",find(root,str));
}
return ;
}
hdu 2846 Repository的更多相关文章
- HDU 2846 Repository (字典树 后缀建树)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- HDU 2846 Repository(字典树,每个子串建树,*s的使用)
Repository Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 2846 Repository (字典树)
RepositoryTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- HDU 2846 Repository(字典树,标记)
题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一 ...
- HDU 2846 Repository(字典树)
字典树较为复杂的应用,我们在建立字典树的过程中需要把所有的前缀都加进去,还需要加一个id,判断它原先是属于哪个串的.有人说是AC自动机的简化,但是AC自动机我还没有做过. #include<io ...
- HDU 2846:Repository(Trie)
http://acm.hdu.edu.cn/showproblem.php?pid=2846 题意:给出N个模式串,再给出M个文本串,问每一个文本串在多少个模式串中出现. 思路:平时都是找前缀的,这里 ...
- Repository HDU - 2846 字典树
题意:给出很多很多很多很多个 单词 类似搜索引擎一下 输入一个单词 判断有一个字符串包含这个单词 思路:字典树变体,把每个单词的后缀都扔字典树里面,这里要注意dd是一个单词 但是把d 和dd都放字典树 ...
- Repository HDU - 2846 (trie)
题中没给范围 所以控制不好数组范围..不是超内存就是runtime.. 好吧 到了晚上终于调出来数组模拟的了 题意: 求含有某字符段的个数 解析: 把每个字符串遍历一遍 以每个元素为起点建树就好了.. ...
- HDU 2846 (AC自动机+多文本匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2846 题目大意:有多个文本,多个模式串.问每个模式串中,有多少个文本?(匹配可重复) 解题思路: 传统 ...
随机推荐
- [收藏]ASP.NET MVC管道详述
ASP.NET MVC从诞生到现在已经好几个年头了,这个框架提供一种全新的开发模式,更符合web开发本质.你可以很好的使用以及个性化和扩展这个框架,但这需要你对它有足够的了解.这篇文章主要从整体角度总 ...
- 蓝牙 BLE GATT 剖析(二)-- GATT UUID and 举例
generic attribute profile (GATT)The Generic Attributes (GATT) define a hierarchical data structure t ...
- POJ 1236 Network of Schools (Tarjan + 缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12240 Accepted: 48 ...
- linux shell send and receive emails
http://www.netcan666.com/2016/02/20/%E5%88%A9%E7%94%A8telnet%E5%9C%A8%E5%91%BD%E4%BB%A4%E8%A1%8C%E5% ...
- TCP的三次握手四次挥手
一.三次握手 1.wireshark 抓包 2.TCP报文手部 注意标志位: 1).同步 SYN = 1 表示这是一个连接请求或连接接受报文. 2).只有当 ACK = 1 时确认号字段才有效.当 A ...
- Linq&Lumbda (2)
"Lambda表达式"是一个匿名函数,它可以包含表达式和语句,并且可用于创建委托或表达式树类型. Lambda 运算符: => 该运算符读为"goes to&quo ...
- jdk 8 lambda表达式 及在Android Studio的使用示例
以前觉得java让人觉得有趣的一个特点是支持:匿名内部类,而最近发现jdk8已支持lambda并有更简便的方式,来实现匿名内部类. 这会让程序员更舒服,更喜欢java. 多年前觉得java语法和C#语 ...
- 使用ASP.NET web API创建REST服务(二)
Creating a REST service using ASP.NET Web API A service that is created based upon the architecture ...
- struts.xml 配置详解
struts.xml是我们在开发中利用率最高的文件,也是Struts2中最重要的配置文件. 一下分别介绍一下几个struts.xml中常用到的标签 1.<include> 利用includ ...
- css spprite应用
(一)实现简单的淘宝带图标侧边栏效果 <!DOCTYPE html> <html lang="en"> <head> <meta char ...