poj1816 Wild Words
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 5567 | Accepted: 1475 |
Description
There are many word patterns and some words in your hand. For each word, your task is to tell which patterns match it.
Input
You can assume that the length of patterns will not exceed 6, and the length of words will not exceed 20.
Output
Sample Input
5 4
t*
?h*s
??e*
*s
?*e
this
the
an
is
Sample Output
0 1 3
0 2 4
Not match
3
Source
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm> const int maxn = ; using namespace std;
int n, m, len, tot = , head[maxn], nextt[maxn], to[maxn], tott = ;
char s[maxn], s2[maxn];
bool flag[maxn], can; vector <int> E[maxn]; struct node
{
char ch;
int tr[];
void clear(char c)
{
ch = c;
memset(tr, , sizeof(tr));
}
}e[maxn * ]; int zhuanhuan(char x)
{
if (x == '?')
return ;
if (x == '*')
return ;
else
return x - 'a';
} void add(int x, int y)
{
to[tott] = y;
nextt[tott] = head[x];
head[x] = tott++;
} void insert(char *ss, int id)
{
int u = ;
len = strlen(ss + );
for (int i = ; i <= len; i++)
{
int t = zhuanhuan(ss[i]);
if (!e[u].tr[t])
{
e[u].tr[t] = ++tot;
e[tot].clear(ss[i]);
}
u = e[u].tr[t];
}
add(u, id); //邻接表
} void dfs(int dep, int u)
{
if (dep == len + )
{
for (int i = head[u]; i; i = nextt[i])
{
int v = to[i];
can = flag[v] = ;
}
if (e[u].tr[]) //trie没走完
dfs(dep, e[u].tr[]);
return;
}
int temp = zhuanhuan(s2[dep]);
if (e[u].tr[temp])
dfs(dep + , e[u].tr[temp]);
if (e[u].tr[])
dfs(dep + , e[u].tr[]);
if (e[u].tr[])
{
dfs(dep + , e[u].tr[]);
dfs(dep, e[u].tr[]);
}
if (e[u].ch == '*') //如果当前点是*
dfs(dep + , u);
} int main()
{
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
scanf("%s", s + );
insert(s, i - );
}
while (m--)
{
can = false;
scanf("%s", s2 + );
len = strlen(s2 + );
memset(flag, false, sizeof(flag));
dfs(, );
if (!can)
{
printf("Not match\n");
continue;
}
for (int i = ; i < n; i++)
if (flag[i])
printf("%d ", i);
printf("\n");
} return ;
}
poj1816 Wild Words的更多相关文章
- POJ1816:Wild Words——题解
http://poj.org/problem?id=1816 比较麻烦的trie. 首先你需要选择针对n还是m建立trie,这里我选择了针对n. 那么就需要面临卡空间的问题. 这里提供了一种链式前向星 ...
- 破壳漏洞利用payload—shellshock in the wild
FireEye关于破壳漏洞(shellshock)在现实中的利用有一篇文章: shellshock in the wild 原文较长,进行了对CGI利用的详细分析,笔者比较感兴趣的是Shellshoc ...
- POJ 1816 Wild Words
Wild Words Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4412 Accepted: 1149 Descri ...
- 【SIGGRAPH 2015】【巫师3 狂猎 The Witcher 3: Wild Hunt 】顶级的开放世界游戏的实现技术。
[SIGGRAPH 2015][巫师3 狂猎 The Witcher 3: Wild Hunt ]顶级的开放世界游戏的实现技术 作者:西川善司 日文链接 http://www.4gamer.net/ ...
- Wild Words
poj1816:http://poj.org/problem?id=1816 题意:给你n个模板串,然后每个串除了字母,还有?或者*,?可以代替任何非空单个字符,*可以替代任何长度任何串,包括空字符串 ...
- 什么是野指针?(What is a wild pointer?)
未被初始化的变量称为野指针(wild pointer).顾名思义,我们不知道这个指针指向内存中的什么地址,使用不当程序会产生各种各样的问题. 理解下面的例子: int main() { int *p; ...
- POJ 3340 & HDU 2410 Barbara Bennett's Wild Numbers(数学)
题目链接: PKU:http://poj.org/problem?id=3340 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2410 Descript ...
- poj 3340 Barbara Bennett's Wild Numbers(数位DP)
Barbara Bennett's Wild Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3153 A ...
- 论文速读(Jiaming Liu——【2019】Detecting Text in the Wild with Deep Character Embedding Network )
Jiaming Liu--[2019]Detecting Text in the Wild with Deep Character Embedding Network 论文 Jiaming Liu-- ...
随机推荐
- Spring学习(1):侵入式与非侵入式,轻量级与重量级
一. 引言 在阅读spring相关资料,都会提到Spring是非侵入式编程模型,轻量级框架,那么就有必要了解下这些概念. 二. 侵入式与非侵入式 非侵入式:使用一个新的技术不会或者基本不改变原有代码结 ...
- NumPy常用函数总结
转载:https://www.cnblogs.com/hd-chenwei/p/6832732.html NumPy库总包含两种基本的数据类型:矩阵和数组,矩阵的使用类似Matlab,本实例用得多的是 ...
- Python学习笔记(二)--变量和数据类型
python中的数据类型 python中什么是变量 python中定义字符串 raw字符串与Unicode字符串 python中的整数和浮点数 python中的bool类型 --- python中的数 ...
- nodepad++ 格式化xml插件
1.用插件管理器安装xmltools插件 2.使用如下菜单格式化xml: 所有插件下载地址: http://sourceforge.net/projects/npp-plugins/files/
- this & super
/* 当本类的成员和局部变量同名用this区分. 当子父类中的成员变量同名用super区分父类. this和super的用法很相似. this:代表一个本类对象的引用. super:代表一个父 ...
- 使用docker国内镜像解决方案
1:蜂巢镜像 https://c.163yun.com/hub#/m/library/ 例如: docker pull hub.c.163.com/library/nginx:1.8 再次执行dock ...
- LAMP环境搭建Wordpress个人博客
LAMP简要介绍 L:LinuxA:Apache(httpd)M:MySQL , MariadbP:php, perl , python 静态资源:图片,文档,视频,HTML代码,CSS代码,js代码 ...
- 201621123037 《Java程序设计》第13周学习总结
作业13-网络 标签(空格分隔): Java 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 思维导图: 其他: 网络编程:由客户端和服务器组成 - 服务器端 第一 ...
- (转)Linux 命令--查看物理CPU个数、核数、逻辑CPU个数
# 总核数 = 物理CPU个数 X 每颗物理CPU的核数 # 总逻辑CPU数 = 物理CPU个数 X 每颗物理CPU的核数 X 超线程数 # 查看物理CPU个数 cat /proc/cpuinfo| ...
- saltstack进阶
查看minion端的文件内容 [root@linux-node2 ~]# cat /etc/resolv.conf # Generated by NetworkManager nameserver 1 ...