显然适用字典树建树,串长和模式串都很小,所以直接递归搜索。同时,适用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系统ifconfig命令找不到,centos ifconfig Command not found

    centos ifconfig Command not found,Linux系统ifconfig命令找不到 >>>>>>>>>>>& ...

  2. Unity3D中读取CSV文件

    直接上代码 Part1: using UnityEngine; using System.IO; using System.Collections.Generic; public class CSV ...

  3. eAccelerator介绍

    加速器 eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除. 它还有对脚本起优化作用,以加 ...

  4. CSS画三角形引发的一些思考

      今天刷知乎时看到了一个问题,有谁能详细讲一下css如何画出一个三角形?怎么想都想不懂? - 知乎.很巧,刚入前端坑的我前不久也遇到过这个问题,今天再来谈一谈这个问题则是因为知乎的一些答案引发了我的 ...

  5. Fragment的生命周期和Activity之间的通信以及使用

    Fragment通俗来讲就是碎片,不能单独存在,意思就是说必须依附于Activity,一般来说有两种方式把Fragment加到Activity,分为静态,动态. 静态即为右键单击,建立一个Fragme ...

  6. OC相关-02:oc和c的基本差异

    前言: 面向过程和面向对象. 简单的说,面向过程就是分析出解决问题所需要的步骤,然后用函数把这些步骤一步一步实现,使用的时候一个一个依次调用. 面向对象是把构成问题事务分解成各个对象,建立对象的目的不 ...

  7. Qt5对付中文真好用

    Qt好多C++程序员都在用,Qt4大家可能用的多,到了Qt5不熟悉的人到是很多,其中我喜欢的特性也是和Qt4大不一样的地方就是对中文的处理. Qt4中使用“QTextCodec::setCodecFo ...

  8. PHP设计模式之:工厂模式

    工厂模式: 由工厂类根据参数来决定创建出哪一种产品类的实例: 工厂类是指包含了一个专门用来创建其他对象的方法的类.所谓按需分配,传入参数进行选择,返回具体的类.工厂模式的最主要作用就是对象创建的封装. ...

  9. 1.document.write(""); 输出语句

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  10. AS3.0声明静态属性和静态方法

    静态属性的变量声明要加static,static var 名称:属性类型=值 静态属性的常量声明要加static或者const,并在声明时就要赋值.static||const var 名称:属性类型= ...