//---------------------------------------------------------------
/*---字典树应用问题。考虑到要查询的次数在10^6,显然直接插入后dfs来查找必然超时间。好在每一个单词长度
---不超过20,这样可以枚举每个单词子串,然后插入即可。例如abc子串为a,b,c,ab,bc,abc。但是要注意的是同一个
---串可能有相同的子串,避免重复插入,可以采用一个节点信息num表示当前插入的是第num个串的子串,可以避免重复插入
*/
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string.h>
typedef long long LL;
using namespace std;
const int maxsize = 26; struct Trie{
Trie(){ memset(next, 0, sizeof(next)); v = 0; num = -1; }
int v;
int num; //标记当前插入的是第num个单词的子串
Trie*next[maxsize];
}; Trie*T;
void insert(int num,char*str){
Trie*p = T;
while (*str != '\0'){
int id = *str++ - 'a';
if (!p->next[id]) p->next[id] = new Trie;
p = p->next[id];
}
if (num != p->num){
p->num=num;
p->v++;
}
} int search(char*str){
Trie*p=T;
while (*str != '\0'){
int id = *str++ - 'a';
if (!p->next[id])return 0;
p = p->next[id];
}
return p->v;
} char str[maxsize];
char temp[maxsize]; int main(){
int n, m;
T = new Trie;
scanf("%d", &n);
while (n--){
scanf("%s", str);
int len = strlen(str);
for (int l = 1; l <= len;l++)
for (int i = 0; i+l<=len;i++){
memcpy(temp, str+i, l);
temp[l] = '\0';
insert(n, temp);
}
}
scanf("%d", &m);
while (m--){
scanf("%s", str);
printf("%d\n",search(str));
}
return 0;
}

  

hdu2846 Repository的更多相关文章

  1. hdu2846 Repository 字典树(好题)

    把每个字符串的所有子串都加入字典树,但在加入时应该注意同一个字符串的相同子串只加一次,因此可以给字典树的每个节点做个记号flag--表示最后这个前缀是属于那个字符串,如果当前加入的串与它相同,且二者属 ...

  2. Repository HDU2846

    极限过的 最原始的方法一层一层建树就好了 #include<bits/stdc++.h> using namespace std; ][]={}; ]={}; ]; ; int pos; ...

  3. DDD 领域驱动设计-谈谈 Repository、IUnitOfWork 和 IDbContext 的实践(3)

    上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext 的实践(2)> 这篇文章主要是对 DDD.Sample 框架增加 Transa ...

  4. Asp.Net Core + Dapper + Repository 模式 + TDD 学习笔记

    0x00 前言 之前一直使用的是 EF ,做了一个简单的小项目后发现 EF 的表现并不是很好,就比如联表查询,因为现在的 EF Core 也没有啥好用的分析工具,所以也不知道该怎么写 Linq 生成出 ...

  5. windows 部署 git 服务器报 Please make sure you have the correct access rights and the repository exists.错误

    这两天在阿里云上弄windows 服务器,顺便部署了一个git服务.根据网上教程一步步操作下来,最后在 remote远程仓库的时候提示 fatal: 'yourpath/test.git' does ...

  6. 初探领域驱动设计(2)Repository在DDD中的应用

    概述 上一篇我们算是粗略的介绍了一下DDD,我们提到了实体.值类型和领域服务,也稍微讲到了DDD中的分层结构.但这只能算是一个很简单的介绍,并且我们在上篇的末尾还留下了一些问题,其中大家讨论比较多的, ...

  7. Repository 仓储,你的归宿究竟在哪?(三)-SELECT 某某某。。。

    写在前面 首先,本篇博文主要包含两个主题: 领域服务中使用仓储 SELECT 某某某(有点晕?请看下面.) 上一篇:Repository 仓储,你的归宿究竟在哪?(二)-这样的应用层代码,你能接受吗? ...

  8. Failure to find xxx in xxx was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced @ xxx

    问题: 在linux服务器上使用maven编译war时报错: 16:41:35 [FATAL] Non-resolvable parent POM for ***: Failure to find * ...

  9. DDD 领域驱动设计-谈谈 Repository、IUnitOfWork 和 IDbContext 的实践(2)

    上一篇:<DDD 领域驱动设计-谈谈 Repository.IUnitOfWork 和 IDbContext 的实践(1)> 阅读目录: 抽离 IRepository 并改造 Reposi ...

随机推荐

  1. SQL小助手——SQL Prompt

    背景: 当数据库设计的比较复杂.庞大时,我们如果对脚本不是很熟悉,就会很难完成看似简单的增.删.改.查的操作.我们需要一款软件来给出相应的提示或帮助,来提高代码的可读性,更快更好的完成任务. 简介: ...

  2. LeetCode -- Implement Stacks using Queue

    Question: Implement the following operations of a queue using stacks. push(x) -- Push element x to t ...

  3. 2017 多校6 String

    多校6 String(ac自动机) 题意: 给一本有\(n\)个单词的字典 \(q\)个查询 \(pref_i,suff_i\) 查询字典里有多少单词前缀匹配\(pref_i\),后缀同时匹配\(su ...

  4. linux下源代码分析和阅读工具比较

    Windows下的源码阅读工具Souce Insight凭借着其易用性和多种编程语言的支持,无疑是这个领域的“带头大哥”.Linux/UNIX环境下呢?似乎仍然是处于百花齐放,各有千秋的春秋战国时代, ...

  5. Eclipse Tomcat 配置问题

    问题描述: Tomcat能启动,ecplise的Console无报错,但是打开http://localhost:8080/报404错误 端口是8080没错,地址也没错,重启了tomcat还是报错,但是 ...

  6. Fix error of "you have been logged on with a temporary profile"

    You have been logged on with a temporary profile on windows2008 R2 After looking into this issue, I ...

  7. tips 前端 背景与元素的透明和模糊

    碰到好几次这样的情况了: 一个带点儿文艺效果 背景图片模糊 而一行别致的文字清晰的悬浮在背景上(口胡,加点美好的想象,生活会更美好) 第一反应是 this is easy. cause i know ...

  8. NOIP 2016 提高组 复赛 Day2T1==洛谷2822 组合数问题

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...

  9. table 实现 九宫格布局

    九宫格布局 最近遇到一个题目,是实现一个九宫格布局的.实现的效果大概是下图这种这样子的: (鼠标悬浮的时候,九宫格的边框颜色是改变的.) 首先想到的是直接使用<table>进行布局,原因很 ...

  10. insmod模块加载过程代码分析1【转】

    转自:http://blog.chinaunix.net/uid-27717694-id-3966290.html 一.概述模块是作为ELF对象文件存放在文件系统中的,并通过执行insmod程序链接到 ...