```cpp
((T+F)+(F+F))+(F+T) F
T+T F
T+F T
F+T T
F+F F
(T) T
(F) F
```
by qq2931451523 @ 2022-10-04 11:48:38
通过 18.24k
by _Remake_ @ 2022-10-04 11:49:18
本题疑似错题,不保证存在靠谱的多项式复杂度的做法。测试数据非常的水,各种做法都可以通过,不代表算法正确。因此本题题目和数据仅供参考。
by _Remake_ @ 2022-10-04 11:49:40
远古时期的圈钱组织出了不少错题,这是其中之一。
by Etinorally @ 2022-10-04 11:50:32
@[bye_wjx](/user/575994) 好的
by qq2931451523 @ 2022-10-04 11:52:06
解决了,这个题目有个坑就是一步只能替换一处,所以用bfs是要把所有位置的替换情况加入到队列中去,附上AC代码
```cpp
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
const int N = 1e6;
string a, b;
struct node{
string s1, s2;
}s[10];
int cnt;
struct node1{
string str;
int step, f;
}deq[N];
int front, tail, ans, tag;
map<string, int> Maps;
int main()
{
cin>>a>>b;
while (cin>>s[cnt].s1>>s[cnt].s2) cnt++;
deq[tail].str = a; deq[tail].step = 0;deq[tail].f = -1;
tail++; Maps[a] = 0;
while (front < tail){
node1 tn = deq[front++];
if (tn.step >= 10) continue;
for (int i = 0; i < cnt; i++){
if (tn.str.find(s[i].s1) == string::npos) continue;
int index = 0;
while (true){
string ts = tn.str;
index = ts.find(s[i].s1, index);
if (index == string::npos) break;
ts.replace(index, s[i].s1.length(), s[i].s2);
if ((Maps.count(ts) && Maps[ts] > tn.step + 1) || !Maps.count(ts)){
Maps[ts] = deq[tail].step = tn.step + 1;
deq[tail].str = ts; deq[tail].f = front - 1;
tail++;
}
index += 1;
if (ts == b){
tag = 1;
ans = deq[tail - 1].step;
break;
}
}
if (tag) break;
}
if (tag) break;
}
if (tag) cout<<ans<<endl;
else cout<<"NO ANSWER!"<<endl;
// int move = tail - 1;
// while (move != -1){
// cout<<deq[move].str<<endl;
// move = deq[move].f;
// }
return 0;
}
```
by qq2931451523 @ 2022-10-04 19:44:09