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个数 ...
随机推荐
- gtid error set test
1.从库报主键重复(Errno: 1062)#create test data 1062create table t1 (id tinyint not null primary key,ename v ...
- 协程实现多并发socket,跟NGINX一样
server: #!/usr/bin/env python # -*- coding: utf-8 -*- # author aliex-hrg import gevent from gevent i ...
- WPF Demo14 依赖属性
using System.Windows; namespace DependencyPropertyDemo1 { public class Student:DependencyObject { pu ...
- PHP localhost和127.0.0.1 的区别
- Firefox不支持event解决方法
IE 中可以直接使用event 对象,而FF 中则不可以,解决方法之一如下: var theEvent = window.event || arguments.callee.caller.argume ...
- mongodb并列查询,模糊查询
在mongodb的查询语句中可以这么写{“a”:$gt(1),"a":$lt(5)} 但这么查询出来的值会做单个条件匹配,最终结果为a大于1的集合+a小于5的集合 如果需要实现去交 ...
- jquery ajax的load()方法和load()事件
1.使用 AJAX 请求来改变 div 元素的文本: $("button").click(function(){ $("div").load('demo_aja ...
- 使用StringEscapeUtils对Java中特殊字符进行转义和反转义
https://blog.csdn.net/zdx1515888659/article/details/84966214 Java中转义字符反斜杠 \ 的代替方法 | repalceAll 内涵解析 ...
- 廖雪峰Java1-4数组操作-4多维数组
二维数组 二维数组就是元素为数组的数组 二维数组每个数组的长度不要求一样.比如 int[][] = { { 1, 2 }, { 3, 4, 5 }, { 6, 7, 8, 9 } } int[][] ...
- C# Socket的Send问题,阻塞线程
Socket sc = comm.connectSocket(ip, port, ReceiveMsg_fromPc); comm.sendSocketMsg16(sc,cmd); sc.Close( ...