Deformation lesson
Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 31348 Accepted Submission (s): 11299
Problem Description
Uh...... In the Metamorphosis class Harry ran into a little trouble, because he was not as Hermione as he could remember all the spells and randomly turned a baseball into a hedgehog or something, but he found a uniform rule of Transfiguration spells: If the spell is a word ending with a B, Then it works just to make a object into a B object.
Harry has already made a list of all the spells he has, and he wants you to help calculate whether he can finish the teacher's homework and turn a B (ball) into a M (Mouse), you know, if he can't do it himself, he has to ask Hermione. and was forced to listen to a lot of good learning. There are multiple sets of input test data. Each group has multiple lines, one word per line, and only lowercase letters, all of which Harry spells. The number 0 indicates the end of a set of inputs. Output "Yes" If Harry can finish his homework, otherwise output "No." (Do not ignore the period) Sample Inputsosoonrivergoesthemgotmoonbeginbig0 Sample Outputyes. Harry can read this mantra: "Big-got-them."
#include <iostream>#include<queue>#include<cstring>#include<string.h>using namespacestd;BOOLvis[ +];Charstr[ +][ +]; BOOLBFsintN) {Queue<int>que; intA, Len; for(inti =0; I < n; i++)//first, the first letter is a b queue. { if(str[i][0] =='b') {Que.push (i); Vis[i]=true;//indicates that the word has been marked. } } while(!Que.empty ()) {a=Que.front (); Que.pop (); Len= strlen (Str[a])-1;//The position of the last character of the string if(Str[a][len] = ='m')//the string is finally m, stating that you can complete { return true; } for(intj =0; J < N; J + +)//Traverse all Strings { if(!vis[j] && str[j][0] = = Str[a][len])//will be the same string as the last string in the queue and not be queued to the team{Que.push (j); VIS[J]=true; } } } return false;} intMain () {inti; I=0; memset (Vis,false,sizeof(VIS));//Initialize Tags while(Cin >> Str[i])//because there are multiple sets of inputs{i++; if(Str[i-1][0] =='0')//if it is 0, a set of data ends, judging, initializing each data { BOOLflag=BFS (i); if(flag) cout<<"Yes."<<Endl; Elsecout<<"No."<<Endl; I=0; memset (Vis,false,sizeof(VIS)); } } return 0;}
Hangzhou Electric ACM 1181 Transformation Course DFS