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-- ...
随机推荐
- mui搜索框 搜索点击事件
<div class="mui-input-row mui-search"> <input type="search" class=" ...
- 在GPT格式的硬盘上,使用EFI启动的方式,安装Win7 64位系统
Win7 sp1 原装系统,用UltraISO(软碟通) 把U 盘制成Win7 安装的启动U盘 将bootmgfw.efi和shell.efi 加到已制好启动U盘的根目录,并在efi/boot/路径下 ...
- 日本IT行业劳动力缺口达22万 在日中国留学生迎来就业好时机 2017/07/18 11:25:09
作者:倪亚敏 来源:日本新华侨报 发布时间:2017/07/18 11:25:09 据日本政府提供的数据,日本2018年应届毕业生的“求人倍率”已经达到了1.78倍.换言之,就是100名大学生 ...
- log4j 配置使用
使用log4j来管理日志信息,非常方便,下面简单介绍一下整个使用流程: 1.创建简单java项目 2.在类路径下新建log4j.properties文件 3.配置log4j.properties文件 ...
- php memcache 使用学习
Memcache是什么Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力.它可以应对任 ...
- Minimum Sum of Array(map迭代器)
You are given an array a consisting of n integers a1, ..., an. In one operation, you can choose 2 el ...
- 学习调用第三方的WebService服务
互联网上面有很多的免费webService服务,我们可以调用这些免费的WebService服务,将一些其他网站的内容信息集成到我们的应用中显示,下面就以查询国内手机号码归属地为例进行说明. 首先安利一 ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- alpha8/10
队名:Boy Next Door 燃尽图 晗(组长) 今日完成 和队友讨论alpha版的最终界面. 明日工作 确定alpha版既定功能的正常使用. 还剩下哪些任务 账号绑定功能以及账单信息的下载. 困 ...
- L1正则化与L2正则化的理解
1. 为什么要使用正则化 我们先回顾一下房价预测的例子.以下是使用多项式回归来拟合房价预测的数据: 可以看出,左图拟合较为合适,而右图过拟合.如果想要解决右图中的过拟合问题,需要能够使得 $ ...