求助,为什么89分最后一个测试点MLE?
查看原帖
求助,为什么89分最后一个测试点MLE?
481471
Eric12楼主2022/8/29 21:50
#include <iostream>
#include <string>
#include <queue>
using namespace std;
string a,b;
int i,index;
struct rule{
	string re;
	string pre;
}r[1001];
struct node{
	string str;
	int step;
};
void fakebfs()
{
	queue<node> q;
	q.push({a,0});
//	cout<<0<<' '<<a<<endl;
	while(!q.empty())
	{
		node x=q.front();
		if(x.str==b)
		{
			cout<<x.step<<endl;
			return;
		}
		if(x.step>=10)
		{
			cout<<"NO ANSWER!"<<endl;
			return;
		}
		for(i=1;i<index;i++)
		{
			int zancun=0,zc=x.str.find(r[i].re,zancun);
			while(zc!=string::npos)
			{
				node next;
				next.str=x.str;
				next.str.replace(zc,r[i].re.size(),r[i].pre);
				next.step=x.step+1;
//				cout<<r[i].re<<' '<<zc<<' '<<zc+r[i].re.size()<<' '<<next.step<<' '<<next.str<<endl;
				q.push(next);
				zancun=zc+1;
				zc=x.str.find(r[i].re,zancun);
			}
		}
		q.pop();
	}
	cout<<"NO ANSWER!"<<endl;
}
int main()
{
	cin>>a>>b;
	for(i=1;cin>>r[i].re>>r[i].pre;i++)
		;
	index=i;
	fakebfs();
	return 0;
}
2022/8/29 21:50
加载中...