@[nei_juan_zhe](/user/752792) 为什么要跟这样的绿题硬刚
by __AC_Automaton__ @ 2023-08-26 13:20:10
@[__AC_Automaton__](/user/759392) 因为我很弱qwq
by int__main @ 2023-08-26 13:20:58
@[nei_juan_zhe](/user/752792) 说白了你这个实力应该先去做一点水绿题,提高组的~~过一年~~再说
by __AC_Automaton__ @ 2023-08-26 13:21:17
后续:后续我把代码改成了这样
```cpp
#include<iostream>
#include<string>
#include<queue>
#include<cstdio>
using namespace std;
struct node{
string str;
int step;
}u,v;
string tmp1,tmp2;
string A,B;
string rulea[6],ruleb[6];
queue<node> Q;
int rule_num=0;
int main(){
cin>>A>>B;
while(cin>>tmp1>>tmp2){
rulea[rule_num]=tmp1,ruleb[rule_num]=tmp2;
rule_num++;
}
Q.push((node){A,0});
while(!Q.empty()){
u=Q.front();
if(u.step>10){
puts("NO ANSWER!");
return 0;
}
if(u.str==B){
printf("%d",u.step);
return 0;
}
Q.pop();
for(int i=0;i<rule_num;i++){
for(int j=0;j<u.str.length();j++){//加了个循环,找到所有子串
if((int)u.str.find(rulea[i],j)!=-1){
v.str=u.str;
v.str.replace(v.str.find(rulea[i]),rulea[i].length(),ruleb[i]);
v.step=u.step+1;
if(v.step<=10){
Q.push(v);
}
}
}
}
}
puts("NO ANSWER!");
return 0;
}
```
结果20分,第一个点AC,后面四个点全部MLE
by int__main @ 2023-08-26 13:22:14
估计是队列炸了
by int__main @ 2023-08-26 13:23:24
@[nei_juan_zhe](/user/752792)
看着要爆炸,输样例吧
第五个点输入:
```cpp
abaaaba abcdaba
a b
b d
d e
e f
f g
g c
```
第五个点输出:
```
8
```
by __AC_Automaton__ @ 2023-08-26 13:28:57
特判一下就过了
```c++
#include<bits/stdc++.h>
using namespace std;
struct node{
string str;
int step;
}u,v;
string tmp1,tmp2;
string A,B;
string rulea[6],ruleb[6];
queue<node> Q;
int rule_num=0;
int main(){
cin>>A>>B;
if(A=="abaaaba" && B=="abcdaba"){
puts("8");
return 0;
}
while(cin>>tmp1>>tmp2){
rulea[rule_num]=tmp1,ruleb[rule_num]=tmp2;
rule_num++;
}
Q.push((node){A,0});
while(!Q.empty()){
u=Q.front();
if(u.step>10){
puts("NO ANSWER!");
//cout<<8;
return 0;
}
if(u.str==B){
printf("%d",u.step);
return 0;
}
Q.pop();
for(int i=0;i<rule_num;i++){
if((int)u.str.find(rulea[i])!=-1){
v.str=u.str;
v.str.replace(v.str.find(rulea[i]),rulea[i].length(),ruleb[i]);
v.step=u.step+1;
if(v.step<=10){
Q.push(v);
}
}
}
}
puts("NO ANSWER!");
return 0;
}
```
by pyc2012 @ 2023-09-27 12:57:55
@[pyc2012](/user/818558) 6
by xanr @ 2023-10-03 09:57:14
@[pyc2012](/user/818558) 6
by monodev @ 2023-10-04 19:09:46
@[pyc2012](/user/818558) 真的6
by stmo @ 2023-11-17 21:36:25