[HDU] [1181] Transformation Course

Problem Description

Loading...

Problem Analysis

Use DFS Recursion to search for whether a word ending in ’m’ exists
Set the Recursion start condition to ‘b’
Initialize for each set of data processed

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<stdio.h>
#include<string.h>
char s[1200][1200];
int flag[1200];
int cnt=0;
bool Can=false;
void judge(char c) {
    if(c=='m')
        Can=true;
    bool win=false;
    for(int i=0; i<cnt; i++) {
        if(s[i][0]==c&&flag[i]==0) {
            flag[i]=1;
            int l=strlen(s[i]);
            judge(s[i][l-1]);
        }
    }
}
int main() {
    while(scanf("%s",s[cnt++])!=EOF) {
        if(s[cnt-1][0]=='0') {
            judge('b');
            printf("%s\n",Can?"Yes.":"No.");
            memset(flag,0,sizeof(flag));
            cnt=0;
            Can=false;
        }
    }
    return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...