最后一个点WA了

P1032 [NOIP2002 提高组] 字串变换

求助求助
by Xie_BR @ 2018-12-01 21:09:04


```c #include<bits/stdc++.h> #define MK 110 using namespace std; string a,b; string x[MK],y[MK]; int ans = 0; int i; map<string,int>stats; string build(string a,string b,string c) { string t = a; string t2 = b; string t3 = c; if(std::string::npos==t.find(b.c_str())) { return string("-1"); } t.replace(t.find(t2.c_str()),t2.size(),t3.c_str()); return t; } void bfs() { queue<string>qu; qu.push(a); while(!qu.empty()) { string f = qu.front(); qu.pop(); if(f==b) { return; } for(int j=1;j<=i;j++) { string t = build(f,x[j],y[j]); if(t=="-1") { continue; } if(stats[t]==0) { stats[t]=stats[f]+1; qu.push(t); }else { if(stats[t]>stats[f]+1) { stats[t]=stats[f]+1; qu.push(t); } } } } } int main() { i=1; cin>>a>>b; while(cin>>x[i]>>y[i]) { i++; if(x[i-1]=="&&&&") { i--; break; } } i--; if(i==0 && a!=b) { printf("NO ANSWER!\n"); return 0; } stats[a]=1; if(a==b) { printf("0"); return 0; } bfs(); if(stats[b]==0) { printf("NO ANSWER!\n"); return 0; } printf("%d",stats[b]-1); return 0; } ```
by Xie_BR @ 2018-12-01 21:09:39


|