uva-310-L--system-暴力枚举
题意:输入四个字符串a,b,w,z,经过一定的替换规则,问w或者w的子串中是否包含z.
替换规则如下.w中的字符a全部替换成a字符串,b字符全部替换成b字符串.
枚举过程,
根据替换规则对w进行替换,生成新的字符串w2,
对w2的子串中长度小于等于z的字符串全部枚举一遍,题目输入限制n<=16,那么,w的子串最多为2^16
#include <iostream>
#include<map>
#include<memory.h>
#include<stdio.h>
#include<string>
#include<queue>
#include<vector>
using namespace std;
string a;
string b;
string bg;
string ed;
map<string, int>maps;
queue<string>q;
int ok = ; void judge(string temp)
{
//枚举字串
for (int i = ;i < temp.size() - ;i++)
{
string temp2 = "";
for (int j = i;j < i + ed.size() && j < temp.size();j++)
{
temp2 += temp[j];
}
if (temp2 == ed)
{
ok = ;
return;
}
else if (maps[temp2] == )
{
q.push(temp2);
maps[temp2] = ;
}
}
} void bfs(string temp)
{ if (temp.size() >= ed.size())
judge(temp);
if (ok)
return;
q.push(temp);
maps[temp] = ;
while (q.empty() == false)
{
temp = q.front();
q.pop();
string temp2 = "";
for (int i = ;i < temp.size();i++)
{
if (temp[i] == 'a')
temp2 += a;
if (temp[i] == 'b')
temp2 += b;
}
judge(temp2);
if (ok)
return;
}
} int main()
{
while (cin >> a)
{
cin >> b >> bg >> ed;
ok = ;
maps.clear();
while (q.empty() == false)
q.pop();
bfs(bg);
if (ok)
cout << "YES" << endl;
else
cout << "NO" << endl; }
}
uva-310-L--system-暴力枚举的更多相关文章
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- Uva 10167 - Birthday Cake 暴力枚举 随机
Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- UVa 10603 Fill [暴力枚举、路径搜索]
10603 Fill There are three jugs with a volume of a, b and c liters. (a, b, and c are positive intege ...
- Gym 101194L / UVALive 7908 - World Cup - [三进制状压暴力枚举][2016 EC-Final Problem L]
题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...
- UVA 10012 How Big Is It?(暴力枚举)
How Big Is It? Ian's going to California, and he has to pack his things, including his collection ...
- uva 11088 暴力枚举子集/状压dp
https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...
- UVA - 11464 Even Parity 【暴力枚举】
题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...
- 紫书 例题 10-2 UVa 12169 (暴力枚举)
就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
随机推荐
- SPI核软件调试结果
SPI核软件调试结果 一.硬件搭建 配置如下: 1.采用手动复位: 2.输入时钟27M,AXI总线工作频率100M: 3.axi_quad_spi 配置为标准模式: 4.配合软件例程的使用,挂载了CP ...
- 回看《例说FPGA》---DDR2控制器集成与读写测试
回看<例说FPGA> ---DDR2控制器集成与读写测试 1.DDR2 IP核的配置 需要弄清楚的选项主要有: PLL reference clock frequency Memory c ...
- Modbus RTU 协议使用汇总
原创地址:https://blog.csdn.net/u012166958/article/details/64920144 标准的Modbus 口是使用RS-232C 兼容串行接口,它定义了连接口的 ...
- Observable讲解
参见这里 总结: Observable是传统观察者+链式模式的函数式实现 Observable官方文档 还是比较喜欢EventBus,简单粗暴,angular-event-service可支持angu ...
- js 格式化时间日期函数小结
下面是脚本之家为大家整理的一些格式化时间日期的函数代码,需要的朋友可以参考下. 代码如下: Date.prototype.format = function(format){ var o = { &q ...
- SpringSecurity-ChannelProcessingFilter的作用
ChannelProcessingFilter决定的是web请求的通道,即http或https. 在springsecurity配置文件中添加这样一行 <intercept-url patter ...
- 服务注册发现consul之一:consul介绍、安装、及功能介绍
Consul 是一套开源的分布式服务发现和配置管理系统,由 HashiCorp 公司用 Go 语言开发.它具有很多优点.包括:基于 raft 协议,比较简洁: 支持健康检查, 同时支持 HTTP 和 ...
- Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label)
ylbtech-Java-Runoob-高级教程-实例-方法:10. Java 实例 – 标签(Label) 1.返回顶部 1. Java 实例 - 标签(Label) Java 实例 Java 中 ...
- go语言学习--map中键值得删除
测试 map1 中是否存在 key1: 在例子 8.1 中,我们已经见过可以使用 val1 = map1[key1] 的方法获取 key1 对应的值 val1.如果 map 中不存在 key1,val ...
- [UE4]使用Is Locally Controlled解决第一人称和第三人称武器位置问题
一.在第一人称网络游戏中,自己看到的是第一人称,其他玩家看到的自己是第三人称. 二.由于第一人称和第三人称是不同的模型,所以枪在模型上面的插槽位置也会不一样. 三.在武器挂载在人物模型的使用,使用“I ...