洛谷 P1032 字串变换
来源:互联网 发布:c语言assert函数 编辑:程序博客网 时间:2024/06/03 19:39
P1032 字串变换
#include<iostream>#include<string>#include<map>using namespace std;map<string,bool> map1;string s1,s2;int n,l=1,r=0;int deep[500000];string que[500000];string sa[7];string sb[7];void in(string s,int deep1){ que[++r]=s; deep[r]=deep1; map1[s]=true;}void do1(string s,string rule1,string rule2,int deep1){ string sx; int k=s.find(rule1,0),i; bool flag; while(k!=string::npos) { flag=false; sx=s; sx.erase(k,rule1.length()); sx.insert(k,rule2); if(sx==s2) { cout<<deep1+1; exit(0); } /*for(i=0;i<didnum;i++) if(did[i]==sx) flag=true;*/ //此处原来是用did记录所有已搜索到的字串,然后每次遍历did数组判断是否重复,后用map优化 if(map1.count(sx)==0) { in(sx,deep1+1); //cout<<sx<<k<<endl; } k=s.find(rule1,k+1); }}void work(){ int i; while(l<=r) { if(deep[l]>=10) { cout<<"NO ANSWER!"; exit(0); } for(i=1;i<=n;i++) { do1(que[l],sa[i],sb[i],deep[l]); } l++; }}int main(){ int i; cin>>s1>>s2; while(cin>>sa[n+1]>>sb[n+1])n++; in(s1,0); work(); cout<<"NO ANSWER!"; return 0;}
阅读全文
0 0
- 洛谷 P1032 字串变换
- 洛谷 P1032 字串变换
- 洛谷 P1032 字串变换
- 洛谷 P1032 字串变换
- 洛谷 P1032 字串变换
- [抄]洛谷 P1032 字串变换
- 洛谷P1032&NOIP2002 字串变换
- 洛谷p1032字串变换c++
- 洛谷 P1032 [NOIP2002 T2] 字串变换
- P1032 字串变换
- BFS之P1032 字串变换
- 双向bfs——洛谷P1032 字串变换
- 洛谷1032 字串变换
- 【洛谷 1032】 字串变换
- 洛谷1032 字串变换
- 洛谷 1032 字串变换
- 【p1032-子串变换】解题记录
- 字串变换
- 范数、测度和距离.
- java 值传递 和 引用传递
- 【解方程】scipy.optimize.solve.
- Python 操作 Json 基础入门
- android repository中部分support库版本整理
- 洛谷 P1032 字串变换
- 最小化安装centos7要做的几件事情
- 拟阵:贪心原理(bzoj 3105: [cqoi2013]新Nim游戏)
- FTPrep, 13 Roman to integer
- $.ajax()方法详解
- 4123
- 关于数组不得不说的事(二维数组)
- linux之shell字符串截取
- 【二叉树】有序数组建平衡二叉树【108. Convert Sorted Array to Binary Search Tree】