题意:输入四个字符串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-暴力枚举的更多相关文章

  1. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  2. Uva 10167 - Birthday Cake 暴力枚举 随机

      Problem G. Birthday Cake Background Lucy and Lily are twins. Today is their birthday. Mother buys ...

  3. UVA 725 division【暴力枚举】

    [题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. uva 11088 暴力枚举子集/状压dp

    https://vjudge.net/problem/UVA-11088 对于每一种子集的情况暴力枚举最后一个三人小组取最大的一种情况即可,我提前把三个人的子集情况给筛出来了. 即 f[S]=MAX{ ...

  8. UVA - 11464 Even Parity 【暴力枚举】

    题意 给出一个 01 二维方阵 可以将里面的 0 改成1 但是 不能够 将 1 改成 0 然后这个方阵 会对应另外一个 方阵 另外一个方阵当中的元素 为 上 下 左 右 四个元素(如果存在)的和 要求 ...

  9. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  10. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

随机推荐

  1. 用DLL实现插件的简单演示

    这是DLL的代码 library MyDll; uses SysUtils, Dialogs, Classes; procedure ShowInfo(info:PChar);stdcall; beg ...

  2. 一个OpenGL小程序

    发个没什么技术含量的文,最近准备通过opengl的学习来好好c++,于是找了网上的教程来搭建opengl的编写环境,建了个空项目,又找了个案例稍微改了改运行了下,还成,ok了~喜不自禁~ 贴个图: 代 ...

  3. js图片预加载后触发操作

    为了使得图片加载完,再触发回调函数,需进行图片预加载处理 function loadImage(url, callback) { var img = new Image(); img.src = ur ...

  4. java反射以及动态代理的学习

    java反射学习 1)字节码文件的三种获取方式 ①:Object类的getClass()方法:对象.getClass() ②:数据类型的静态的class属性:类名.class ③:通过Class类的静 ...

  5. PREV-2_蓝桥杯_打印十字图

    问题描述 小明为某机构设计了一个十字型的徽标(并非红十字会啊),如下所示: ..$$$$$$$$$$$$$....$...........$..$$$.$$$$$$$$$.$$$$...$...... ...

  6. 传统Java Web(非Spring Boot)、非Java语言项目接入Spring Cloud方案

    技术架构在向spring Cloud转型时,一定会有一些年代较久远的项目,代码已变成天书,这时就希望能在不大规模重构的前提下将这些传统应用接入到Spring Cloud架构体系中作为一个服务以供其它项 ...

  7. 提取字符串substring()

    substring() 方法用于提取字符串中介于两个指定下标之间的字符. 语法: stringObject.substring(startPos,stopPos)  参数说明: 注意: 1. 返回的内 ...

  8. mybatisz中一个可以替代between..and 的技巧

    用mybatis进行时间段筛选时,如果,查询本日,本月的信息量,我们可以使用like concat()函数来替换between..and <select id="queryMyStaf ...

  9. maven release版本不自动更新的原因

    如果是release版本,首先从本地查找对应的版本,如果有,则使用本地,否则从远程服务器下载. 这也就是为什么我们有时想要去更新release版本的jar包,会发现无法更新,除非删除本地仓库中的版本. ...

  10. Jmeter(三十三)Stepping Thread Group

    碰巧最近在做性能测试,就记一下Jmeter的第三方插件Stepping Thread Group. 具体一些插件信息,可以去:jmeter-plugins.org去进行下载. 该插件目前是已经被弃用的 ...