社区讨论
RE 60pts求调
P1032[NOIP 2002 提高组] 字串变换(疑似错题)参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mhjteqhd
- 此快照首次捕获于
- 2025/11/04 08:12 4 个月前
- 此快照最后确认于
- 2025/11/04 08:12 4 个月前
CPP个人看着没什么问题
#include <bits/stdc++.h>
using namespace std ;
int ans , n ;
string s1 , s2 , x , y ;
set <string> st ;
map <string , vector <string> > mp ;
map <string , int > mp1 ;
struct node {
string x ; int y ;
};
queue <node> q ;
void bfs () {
string p ;
q.push (node {s1 , 0}) ;
mp1 [x] = 1 ;
while (! q.empty ()) {
string us = q.front ().x ; int uum = q.front ().y ; q.pop () ;
if (uum > 10) continue ; if (us == s2) ans = min (ans , uum) ;
for (auto x : st)
for (int i = 0 ; i <= us.size () - x.size () + 1 ; i ++) {
p = us ;
if (us.substr (i , x.size ()) != x) continue ;
int rbd = i ;
p.erase (rbd , x.size ()) ;
for (auto k : mp [x]) {
string r = p ;
r.insert (rbd , k) ;
if (mp1 [r]) continue ;
mp1 [r] = 1 ;
q.push (node {r , uum + 1}) ;
}
}
}
}
signed main () {
ios::sync_with_stdio (false) ;
cin.tie (NULL) ; cout.tie (NULL) ;
ans = 114514 ;
cin >> s1 >> s2 ;
while (cin >> x >> y) {
n ++ ;
st.insert (x) ;
mp [x].push_back (y) ;
}
bfs () ;
if (ans == 114514) cout << "NO ANSWER!" ;
else cout << ans ;
return 0 ;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...