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-- ...
随机推荐
- 423. Valid Parentheses【LintCode java】
Description Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine ...
- 常用monkey_app稳定性
Monkey稳定性测试 1 前言 为方便快速上手Monkey测试相关问题,针对测试中发现的Monkey问题进行了整理总结,供定位Monkey参考. 2 关于Monkey测试 2 ...
- 设计模式C++实现
准备写一系列笔记用来记录学习设计模式的过程,同时写出自己对几种主要的设计模式的理解,以及编码实现,同时总结. 主要参考书籍就是 <Head First Design Patterns>这本 ...
- python购物车优化
一.需求分析 拥有用户接口和商家接口 用户能够进行消费记录查询,充值,购物等功能,消费记录存储于数据库 商家可以进行商品的增删改等操作 二.程序流程图 程序大致流程图如下: 三.代码实现 本程序分成两 ...
- JAVA学习笔记--初识容器类库
一.前言 JAVA中一切皆为对象,因而,持有对象显得尤为重要. 在JAVA中,我们可以通过创建一个对象的引用的方式来持有对象: HoldingObject holding; 也可以创建一个对象数组来持 ...
- Unity学习笔记草稿篇(一)为unity配置添加VS智能感知
1. 打开要编辑的配置文件: 2. 菜单栏 -> xml -> 架构(schema) -> 添加或使用xsd.如下图所示:
- MobSF 框架安装使用部署
1.MobSF 简介 MobSF是Mobile Security Framework的缩写,这是一款智能化的开源移动应用(Android.IOS.Windows)测试框架,可以对应用进行动态.静态分析 ...
- ES6的新特性(21)——Proxy
Proxy 概述 Proxy 用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”(meta programming),即对编程语言进行编程. Proxy 可以理解成,在目标对 ...
- Java:有关自定数组的学习
Java:有关==自定数组==的学习 在 ==<Java程序设计与数据结构教程>== 里我在==P212~P213==页看到一个GradeRange的程序,它用的数组是自定设定的Grade ...
- 第四周 实验一 Java开发环境的熟悉 报告
Java开发环境的熟悉 实验内容 1.IDEA的安装过程 2.使用IDEA代替虚拟机运行.编译.调试Java程序 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)&g ...