so soon river goes them got moon begin big 0
Yes.Harry 可以念这个咒语:"big-got-them".HintHint
简单深搜
#include <stdio.h> #include <string.h> int l = 0,flag = 0; struct Node { char head,end; } c[10000]; int vis[10000]; void dfs(char ch) { int i; if(ch == 'm') flag = 1; if(flag) return; for(i = 0; i<l; i++) { if(vis[i]) continue; if(c[i].head == ch) { vis[i] = 1; dfs(c[i].end); vis[i] = 0; } } } int main() { char s[100]; int i; while(~scanf("%s",s)) { if(!strcmp(s,"0")) continue; l = 0; c[l].head = s[0]; c[l].end = s[strlen(s)-1]; l++; while(scanf("%s",s),strcmp(s,"0")) { c[l].head = s[0]; c[l].end = s[strlen(s)-1]; l++; } flag = 0; for(i = 0; i<l; i++) { if(c[i].head == 'b') { memset(vis,0,sizeof(vis)); vis[i] = 1; dfs(c[i].head); } if(flag) break; } if(flag) printf("Yes.\n"); else printf("No.\n"); } return 0; }
而由于这题的测试数据很弱,只有第一组是yes,其他都是no
所以下面的代码也能A
#include <stdio.h> int main() { char c; int flag = 1; while(~scanf("%c",&c)) { if(c == '0') { if(flag) { printf("Yes.\n"); flag = 0; } else printf("No.\n"); } } return 0; }