显然适用字典树建树,串长和模式串都很小,所以直接递归搜索。同时,适用bk标记当前的查询次数(排除不同模式的多次查询成功,如*t*)。需要主要的是,居然存在同名文件!!!。

 /* 2279 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
using namespace std; #define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct node_t {
int in;
int c;
int next[];
} node_t; const int maxl = ;
const int maxn = ;
node_t nd[maxn*maxl];
char s[maxl], d[maxl];
int dl, sl;
int L = maxn*maxl, bk;
int n, m, ans; void init() {
memset(nd, , sizeof(node_t)*L);
L = bk = ;
} void insert() {
int i = , id;
int p = , q; while (s[i]) {
id = s[i] - 'a';
q = nd[p].next[id];
if (q == )
q = nd[p].next[id] = L++;
p = q;
++i;
}
++nd[p].c;
} void search(int p, int l) {
if (l == dl) {
if (nd[p].c && nd[p].in!=bk) {
ans += nd[p].c;
nd[p].in = bk;
}
return ;
} if (d[l] == '?') {
for (int i=; i<; ++i)
if (nd[p].next[i])
search(nd[p].next[i], l+); } else if (d[l] == '*') {
search(p, l+);
for (int i=; i<; ++i)
if (nd[p].next[i])
search(nd[p].next[i], l); } else {
int id = d[l] - 'a';
if (nd[p].next[id])
search(nd[p].next[id], l+); }
} void handle() {
int i = ; sl = strlen(s);
dl = ;
while () {
while (s[i]=='*'&&s[i+]=='*')
++i;
if (i >= sl)
break;
d[dl++] = s[i++];
}
d[dl] = '\0';
} int main() {
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif while (scanf("%d %d",&n,&m)!=EOF) {
init();
for (i=; i<n; ++i) {
scanf("%s", s);
insert();
}
while (m--) {
scanf("%s", s);
handle();
ans = ;
search(, );
++bk;
if (ans)
printf("%d\n", ans);
else
puts("Not match");
}
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}

【HDOJ】2279 File Search Tool的更多相关文章

  1. 【HDOJ】2222 Keywords Search

    AC自动机基础题. #include <iostream> #include <cstdio> #include <cstring> #include <cs ...

  2. 【python】类file文件处理

    [flush方法] 通常由于缓冲,write不将数据写入文件,而是写入内存的缓冲区,需要使用flush写入文件,并清空缓冲区 文件的flush方法的作用是强制清空缓存写入文件.默认每行flush一下? ...

  3. 【LeetCode】Validate Binary Search Tree ——合法二叉树

    [题目] Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defin ...

  4. 【LeetCode】二叉查找树 binary search tree(共14题)

    链接:https://leetcode.com/tag/binary-search-tree/ [220]Contains Duplicate III (2019年4月20日) (好题) Given ...

  5. 【leetcode】 Unique Binary Search Trees (middle)☆

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. 【HDU】2222 Keywords Search

    [算法]AC自动机 [题解]本题注意题意是多少关键字能匹配而不是能匹配多少次,以及可能有重复单词. 询问时AC自动机与KMP最大的区别是因为建立了trie,所以对于目标串T与自动机串是否匹配只需要直接 ...

  7. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  8. 【HDOJ】1547 Bubble Shooter

    两次BFS,一次扫描关联点.一次扫描可能掉落的情况(即再次扫描所有非爆炸的联通点).余下未被扫描的点均爆炸. #include <cstdio> #include <cstring& ...

  9. 【转】MAT(Memory Analyzer Tool)工具入门介绍

    1.MAT是什么? MAT(Memory Analyzer Tool),一个基于Eclipse的内存分析工具,是一个快速.功能丰富的JAVA heap分析工具,它可以帮助我们查找内存泄漏和减少内存消耗 ...

随机推荐

  1. Linux Bash算数运算方法小结

    A= B= 方法1:let(中间无空格) let C=$A+$B 方法2:$[  ] C=$[$A+$B] 方法3:$(()) C=$(($A+$B)) 方法4:expr(中间有空格) C=`expr ...

  2. 过滤器(filter)实现用户登录拦截

    过滤器(filter)实现用户登录拦截 >>>>>>>>>>>>>>>>>>>> ...

  3. Java-hibernate的映射文件

    Hibernate 需要知道怎样去加载(load)和存储(store)持久化类的对象.这正是 Hibernate 映 射文件发挥作用的地方.映射文件告诉 Hibernate 它应该访问数据库(data ...

  4. 初识 .NET平台下作业调度器——Quartz.NET

    Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于winform和asp.net应用中.它提供了巨大的灵活性而不牺牲 ...

  5. java - 异常浅谈

    java提供异常处理机制中,可以分为RuntimeException和checked Exception两种. RuntimeException 是运行时异常,是程序本身无法解决的.例如,对于一个用户 ...

  6. 文件上传利器SWFUpload使用指南

    这里就不再介绍什么是SWFUpload啦,简单为大家写一个简单关于SWFUpload的Demo. 1.把SWFUpload 相关的文件引用进来 2.创建upload.aspx页面(页面名称可自定义), ...

  7. Delphi Excel

    用delphi写excel文件 2007-03-18 21:12 1.引用:      Excel2000, OleServer,Comobj, StdCtrls 2.声明变量:     ExcelA ...

  8. Error Domain=com.google.greenhouse Code=-102

    *** Terminating app due to uncaught exception 'com.google.greenhouse', reason: 'Error Domain=com.goo ...

  9. React学习笔记(二) 组件状态

    组件的状态(this.state): 组件免不了要与用户互动,React 的一大创新,就是将组件看成是一个状态机,一开始有一个初始状态,然后用户互动,导致状态变化,从而触发重新渲染 UI getIni ...

  10. 转载:Python正则表达式

    原文在  http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html 1. 正则表达式基础 1.1. 简单介绍 正则表达式并不是Python ...