Metamorphosis Lesson (DFS hdu 1181)

Source: Internet
Author: User

Deformation lesson

Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 19133 Accepted Submission (s): 6892


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. HintHint the second time to do this problem, began to time out. Advance pre-judgment to do not extend to the node, do not call DFS and then determine if pity Dorado is able to expand. For this reason, the timeout is 15ms.
1 /*******************************2 3 date:2015-12-08 21:36:484 AUTHOR:WQJ ([email protected])5 Link:http://www.cnblogs.com/a1225234/6 Name:hdu 11817 8 ********************************/9#include <iostream>Ten#include <cstdio> One#include <algorithm> A#include <cmath> -#include <cstring> -#include <string> the#include <Set> -#include <vector> -#include <queue> -#include <stack> + #defineLL Long Long - using namespacestd; + intK; A Charch[ -][2]; at Chara[ -]; - BOOLFlag; - BOOLvis[ -]; - voidDfsintN) - { -     inti,j; invis[n]=1; -     if(ch[n][1]=='m') to     { +flag=1; -         return; the     } *      for(i=0; i<k;i++) $     {Panax Notoginseng         if(ch[i][0]==ch[n][1]) -         { the             if(Vis[i])Continue; + DFS (i); Avis[i]=0; the             if(flag)return; +         } -     } $     return; $ } - intMain () - {     theFreopen ("In.txt","R", stdin); -     inti,j;Wuyi      while(SCANF ("%s", ch[0])!=EOF) the     { -         intLen=strlen (ch[0]); Wuch[0][1]=ch[0][len-1]; -          for(i=1;; i++) About         { $scanf"%s", a); -             if(a[0]=='0') -                  Break; -             intlen=strlen (a); Ach[i][0]=a[0]; +ch[i][1]=a[len-1]; the         } -k=i+1; $flag=0; thememset (Vis,0,sizeof(Vis)); the          for(i=0; i<k;i++) the         { the             if(ch[i][0]=='b') -             { in DFS (i); thevis[i]=0; the             } About         } theprintf"%s\n", Flag?"Yes.":"No."); the     } the     return 0; +}

Metamorphosis Lesson (DFS hdu 1181)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.