万人过的题诶~~
是不是数组开小了 如果数组大了也有可能
主要是数组越界
by 逸少 @ 2019-04-29 14:55:01
$\color{red}\text{map是个好东西QAQ}$
by eee_hoho @ 2019-04-29 15:00:05
@[eee_hoho](/space/show?uid=73231) 您tql
by Infiltrator @ 2019-04-29 15:00:25
```
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
string a,b;
int p=0;
string aa[7],bb[7],ss[500050];
map <string,int> f;
void bfs()
{
int h=0,t=1;
ss[t]=a;
while(h<t)
{
h++;
if(ss[h]==b)
{
cout<<f[ss[h]];
exit(0);
}
if(f[ss[h]]>10)
break;
int l=ss[h].size();
for(int i=1;i<=p;i++)
{
for(int j=0;j<l;j++)
{
int r=ss[h].find(aa[i],j);
if(r!=string::npos)
{
string stt=ss[h];
stt.replace(r,aa[i].size(),bb[i]);
if (!f[stt])
{
ss[++t]=stt;
f[stt]=f[ss[h]]+1;
}
}
}
}
}
}
int main()
{
cin>>a>>b;
string st1,st2;
while(cin>>st1>>st2)
{
aa[++p]=st1;bb[p]=st2;
}
bfs();
if (!f[b]||f[b]>10)cout<<"NO ANSWER!"<<endl;
return 0;
}
```
搜索的时候没判重,所以RE了,~~开个map美滋滋QWQ~~,给你改好了。~~
by eee_hoho @ 2019-04-29 15:10:45
@[坐山客](/space/show?uid=73983)
by eee_hoho @ 2019-04-29 15:10:56
@[eee_hoho](/space/show?uid=73231) 、
初四大神太强了
我这个AFO选手向您致以最崇高的敬礼!!!!!
$\color{pink}\text
{
初四大神太强了
我这个AFO选手向您致以最崇高的敬礼!!!!!}$
by Infiltrator @ 2019-04-29 15:14:26