hdu1181 deformation course (Vector container +dfs)

Source: Internet
Author: User

Deformation lessonTime limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 16998 Accepted Submission (s): 6128


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 Input
Sosoonrivergoesthemgotmoonbeginbig0

Sample Output
Yes. Hint HintHarry can read this mantra: "Big-got-them".

Sourcegardon-dygg Contest 1 Feel this problem is really a good question, and really feel. Because the previous contact is a one-to value, suddenly come out a pair of many values let me a little overwhelmed. Because a few days ago did a nyoj20 stingy country, know a vector container. It was done with a vector.

Vector container, used for the first time. Understanding the vector array is a good idea, but I don't know why it becomes a two-dimensional array. where Map[i][j] may be more difficult to understand.

Example: map[1]=2,map[1]=3,map[1]=4; then map[1][0] equals 1,map[1][1]=3,map[1][2]=4. and map[1].size () = 3; (because map[1] only 2,3,4 three values);

The record of the problem:

Ha ha.. And then I knew where it was wrong.

#include <stdio.h> #include <vector> #include <string.h>using namespace std;vector<int>fa[130 ];int flag,vis[130][130];void Find (int x,int root) {for (int i=0;i<fa[x].size (); i++) {if (fa[x][i]!=root&&! VIS[I][X]) Vis[i][x]=1,find (fa[x][i],root);//I was wrong to put Vis[i][x] behind the recursion. Hey don't know what to think if (Fa[x][i]==root&&!vis[i][x]) {flag=1;break;}}} int main () {char str[20];int len;while (scanf ("%s", str)!=eof) {memset (fa,0,sizeof (FA)); Memset (vis,0,sizeof (Vis)); Len =strlen (str); Fa[str[0]].push_back (Str[len-1]), while (scanf ("%s", str)!=eof) {if (str[0]== ' 0 ') Break;elselen=strlen ( STR), Fa[str[0]].push_back (Str[len-1]);} Flag=0;find (98,109); if (flag) printf ("yes.\n"); elseprintf ("no.\n");}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu1181 deformation course (Vector container +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.