莫名re,悬关
查看原帖
莫名re,悬关
1088663
zzzyyyyhhhhh楼主2024/1/25 20:01
#include<bits/stdc++.h>
using namespace std;
string a,b;
int cnt,l[7];
int ans=1e9;
map<string,bool> d;
string a1[7],b1[7];
struct node
{
	int an;
	string s;
};
queue<node> c;
void dfs(int an,string s)
{
	if(d[s])return;
	d[s]=1;
	if(an>10)return;
	if(s==b)ans=min(ans,an);
	for(int i=1;i<=cnt;i++)
	{
		for(int j=0;j+l[i]<=s.length();j++)
		{
			if(s.substr(j,l[i])==a1[i])
			{
				c.push({an+1,s.substr(0,j)+b1[i]+s.substr(j+l[i],s.length()-j-l[i])});
			}
		}
	}
}
int main()
{
	cin>>a>>b;
	while(cin>>a1[++cnt]>>b1[cnt])
	{
		l[cnt]=a1[cnt].length();
	}
	cnt--;
	c.push({0,a});
	while(c.front().an<=10)
	{
		dfs(c.front().an,c.front().s);
		c.pop();	
		if(ans!=1e9){cout<<ans;return 0;}
	}
	//dfs(0,a);
	cout<<"NO ANSWER!";
}


数据

program procedure
g ce
ra dur
am ee
ee am

在Linux会re,Windows能过

2024/1/25 20:01
加载中...