题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251
题意:先给出字典。每次查询一个单词,求以该单词为前缀的个数。
思路:裸字典树
代码
#include
#include
#include
#include
#include
#include
using namespace std;
#define...
分类:
其他好文 时间:
2015-08-15 11:56:34
阅读次数:
118
struct node{ int next[27]; int v; void init() { v=0; memset(next,-1,sizeof(next)); }};node L[1000500];int tot=0;void add(...
分类:
其他好文 时间:
2015-08-15 10:18:50
阅读次数:
80
1.题目描述:点击打开链接
2.解题思路:本题利用字典树解决。本题要求查找所有的B[j]在A[i]中出现的总次数。那么我们可以建立一颗字典树,将所有的B[j]插入字典树,由于一个串的所有字串相当于它所有后缀的前缀。因此在查找时候,只需要查找A[i]的每一个后缀即可,然后累加这个后缀的前缀个数,即可得到该后缀中子串的个数,所有后缀的值相加,就是最终的答案。
3.代码:
#pragma comm...
分类:
其他好文 时间:
2015-08-14 22:47:44
阅读次数:
349
题意:
f(A,B)f(A,B)表示:B在A中作为子串出现的次数。
题目给出n个证据,m个子弹
AiA_i是证据,BiB_i是子弹,题目问:所有BiB_i对每个AiA_i造成的伤害是多少,即每个BiB_i在AiA_i中出现的次数总和。
解析:
不会AC自动机,所以就用字典树水了一发,没想到过了。
先把所有的BiB_i插入字典树中,然后枚举每个AiA_i的后缀,查询每个前缀在...
分类:
其他好文 时间:
2015-08-13 20:14:21
阅读次数:
161
题意:给出两个集合S和T,集合中每个元素是个字符串,而T集合中任一元素都是个子弹,可以打S中的任一怪物,如果子弹是怪物的子串,那么才有伤害值1,若在怪物中出现多次,次数为该子弹打到该怪物的伤害值。每个子弹可以射不同怪物分别一次。求用完所有子弹,每个怪物受到的伤害值。思路:先将所有子弹插到Trie树中...
分类:
其他好文 时间:
2015-08-13 19:34:43
阅读次数:
246
Hat’s WordsTime Limit:1000MSMemory Limit:32768KB64bit IO Format:%I64d & %I64uSubmitStatusPracticeHDU 1247DescriptionA hat’s word...
分类:
其他好文 时间:
2015-08-13 17:49:43
阅读次数:
105
#include#include#include#define maxn 10struct trie{ trie *next[10]; int sum; int flag;};trie *root;char way[5010][10];void init(){ root=(t...
分类:
其他好文 时间:
2015-08-12 18:24:33
阅读次数:
96
给你一堆字符串,然后再给你几个查询,前面那些字符串中有多少个包含了这个串。所以可以把开始inset()的字符遍历一遍,同时可能出现该字符串在某个字符串中有多次出现,所以还要用flag标记,来区分不同的串。#include#include#includestruct trie{ int flag...
分类:
其他好文 时间:
2015-08-12 16:35:22
阅读次数:
115
1.动态申请的内存用完以后要释放,否则超内存。
2.代码:
#include
#include
#include
using namespace std;
struct Node
{
int cnt;
Node *next[10];
void init()
{
cnt=0;
for(int i=0;i<10;i++)
...
分类:
其他好文 时间:
2015-08-11 23:31:32
阅读次数:
157
1.这是一道字典树的题,但用map也可以做
2.代码:
#include
#include
#include
#include
using namespace std;
map mp;
char s[30100],ss[15];
int main()
{
scanf("%s",s);
while(1)
{
scanf("%s",s);
...
分类:
其他好文 时间:
2015-08-11 18:52:33
阅读次数:
117