每日一题 day19 打卡

Analysis

广搜+map判重

用find寻找字串,再用replace替换字串

这里的map相当于正常广搜的一个book的作用

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#define int long long
#define maxn 6+10
using namespace std;
inline void write(int x)
{
if(x<){putchar('-');x=-x;}
if(x>)write(x/);
putchar(x%+'');
}
string a,b;
string ca[maxn],cb[maxn];
map<string,int> m;
int len=;
queue<string> cq;
queue<int> sq;
inline int bfs()
{
while(!cq.empty()&&cq.front()!=b&&sq.front()<=)
{
if(m[cq.front()]==)
{
cq.pop();
sq.pop();
continue;
}
m[cq.front()]=;
for(int i=;i<=len;i++)
{
string ns=cq.front();
while()
{
int site=ns.find(ca[i]);
if(site==-) break;
string ss=cq.front();
ss.replace(site,ca[i].size(),cb[i]);
cq.push(ss);
sq.push(sq.front()+);
ns[site]='#';
}
}
}
if(cq.empty()||sq.front()>) return -;
else return sq.front();
}
signed main()
{
cin>>a>>b;
while(cin>>ca[len]>>cb[len]) len++;
len--;
if(len==&&a!=b)
{
cout<<"NO ANSWER!";
return ;
}
cq.push(a);
sq.push();
int ans=bfs();
if(ans==-) cout<<"NO ANSWER!";
else write(ans);
return ;
}

请各位大佬斧正(反正我不认识斧正是什么意思)

最新文章

  1. js 调试
  2. Premier使用笔记
  3. 【hadoop】——修改hadoop FileUtil.java,解决权限检查的问题
  4. 4、面向对象以及winform的简单运用(继承与多态、命名空间与类库)
  5. 屏蔽wordpress升级提示
  6. Linux系统内核制作和内核模块的基础
  7. Webform之FileUpload(上传按钮控件)简单介绍及下载、上传文件时图片预览
  8. models中的pk主键用法
  9. Chrome浏览器,处理input自动填充时带黄色背景色
  10. odoo8 元素简介
  11. react写一个todo
  12. 如何构造树状 JSON 数据 JSON-Tree
  13. Springboot Thymeleaf 发邮件 将html内容展示在邮件内容中
  14. Java对象的克隆
  15. POJ-1887 Testing the CATCHER(dp,最长下降子序列)
  16. vue.js学习 自定义过滤器使用(2)
  17. ‘,’之后要留空格,如 Function(x, y, z)
  18. 论文笔记:空间变换网络(Spatial Transformer Networks)
  19. 022——VUE中remove()方法的使用:
  20. python3安装 feedparser

热门文章

  1. pymysql 模块简单使用
  2. Django的Xadmin使用
  3. vue页面params传值的必须传name
  4. Deep one-class classification
  5. 访问Harbor报502 Bad Gateway
  6. js 使用 &quot;use strict&quot;
  7. 实现负载均衡的小demo
  8. Jenkins的语法之pipeline
  9. 纯 CSS 画 iphone
  10. vue-element-admin 前端框架 使用感触