HDU 1181 Transformation Course (DFS)

Source: Internet
Author: User

Deformation lesson

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


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. HintHintharry can read this mantra: "Big-got-them".

Sourcegardon-dygg Contest 1recommendjgshining | We have carefully selected several similar problems for you:1180 1258 1728 1372 1072

Deep search of the foundation, the last letter of a word if it is the same as the first letter of another word, it can be changed into this word, and judging whether it can be changed from B to M, the letter can be converted into a digital judgment to reduce the difficulty of judging.

Test instructions: Chinese question.

Attached code:

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 intss[ -][ -],fail;6 7 voidDFS (intk)8 {9     if(fail)Ten         return; One     if(k=='m'-'a')//find m, end deep search A     { -Fail=1; -         return; the     } -      for(intI=0;i< -; i++)//start searching in 26 alphabetical order -     { -         if(Ss[k][i]) +         { -ss[k][i]=0;//the searched mark is 0. + DFS (i); A         } at     } - } -  - intMain () - { -     Chars[ -]; in      while(~SCANF ("%s", s))//The input must be cycled multiple times -     { to         if(s[0]=='0'&&strlen (s) = =1) +              Break; -memset (SS,0,sizeof(ss)); the         intx, y; *x=s[0]-'a';//Convert letters to numbers $Y=s[strlen (s)-1]-'a';Panax Notoginsengss[x][y]=1;//the first letter of each word can be converted with the last letter -          while(~SCANF ("%s", s)) the         { +             if(s[0]=='0'&&strlen (s) = =1)//output 0 jump out of loop A                  Break; thex=s[0]-'a'; +Y=s[strlen (s)-1]-'a'; -ss[x][y]=1; $         } $Fail=0; -DFS (1);//start with the B-Letter search . -         if(fail) printf ("yes.\n"); the         Elseprintf"no.\n"); -     }Wuyi     return 0; the}

HDU 1181 Transformation Course (DFS)

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.