显然适用字典树建树,串长和模式串都很小,所以直接递归搜索。同时,适用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. ListView simpleAdapter的基本使用

    使用simpleAdapter的数据用一般都是HashMap构成的List,list的每一节对应ListView的每一行.HashMap的每个键 值数据映射到布局文件中对应id的组件上.因为系统没有对 ...

  2. Kali Linux 2.0: 安装之后的操作

    1. 添加官方软件库 1) 编辑/etc/apt/sources.list leafpad /etc/apt/sources.list 2) 用#注释掉原有的内容,并添加下述内容: # Regular ...

  3. CentOS隐藏nginx版本号

    在/usr/local/nginx/conf/目录中,修改nginx.conf文件 在http {  }段中加入 http { server_tokens off; }

  4. SQL语句中格式化时间

    给数据库中的字段格式化(): to_char(CREATETIME,'yyyy-MM-dd') 给程序中的字段格式化(InTime为数据库字段): InTime = to_date( '" ...

  5. .NET多线程同步方法详解

    .NET多线程同步方法详解(一):自由锁(InterLocked) .NET多线程同步方法详解(二):互斥锁(lock) NET多线程同步方法详解(三):读写锁(ReadWriteLock) .NET ...

  6. [Twisted] transport和protocol解耦

    Twisted中transport和protocol完全解耦. 这样设计的优点: 1.不同的Protocol协议实现可以重用相同类型的transport. 2.方便测试:假如测试一个协议实现,可以使用 ...

  7. 1 Yoga3 系统装机总结.

    1- Yoga 3 存在串口驱动不安装, 那么触摸屏不能用的情况, 打破了以往对触摸屏-"纯外设" 的设想, 与系统有关!!! 2- 系统安装总结: 1) BIOS中设置UEFI ...

  8. 生产者与消费者(二)---await与 signal

    前面阐述了实现生产者与消费者问题的一种方式:wait() / notify()方法,本文继续阐述多线程的经典问题---生产者与消费者的第二种方式:await() / signal()方法. await ...

  9. 237. Delete Node in a Linked List(C++)

    237. Delete Node in a Linked Lis t Write a function to delete a node (except the tail) in a singly l ...

  10. PC110305/UVA10188

    根据我的规律,每天solved3题就感觉不行了~但是今天好像做水题做上瘾了,不过PC的题目尽管水,水得还是可以让人有进步. 这题OJ自动测评真心坑,题目看起来十分简单,测评返回三种可能: Accept ...