标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 19133 Accepted Submission(s):
6892
1 /******************************* 2 3 Date : 2015-12-08 21:36:48 4 Author : WQJ (1225234825@qq.com) 5 Link : http://www.cnblogs.com/a1225234/ 6 Name : hdu 1181 7 8 ********************************/ 9 #include <iostream> 10 #include <cstdio> 11 #include <algorithm> 12 #include <cmath> 13 #include <cstring> 14 #include <string> 15 #include <set> 16 #include <vector> 17 #include <queue> 18 #include <stack> 19 #define LL long long 20 using namespace std; 21 int k; 22 char ch[500][2]; 23 char a[50]; 24 bool flag; 25 bool vis[500]; 26 void dfs(int n) 27 { 28 int i,j; 29 vis[n]=1; 30 if(ch[n][1]==‘m‘) 31 { 32 flag=1; 33 return; 34 } 35 for(i=0;i<k;i++) 36 { 37 if(ch[i][0]==ch[n][1]) 38 { 39 if(vis[i]) continue; 40 dfs(i); 41 vis[i]=0; 42 if(flag) return; 43 } 44 } 45 return; 46 } 47 int main() 48 { 49 freopen("in.txt","r",stdin); 50 int i,j; 51 while(scanf("%s",ch[0])!=EOF) 52 { 53 int len=strlen(ch[0]); 54 ch[0][1]=ch[0][len-1]; 55 for(i=1;;i++) 56 { 57 scanf("%s",a); 58 if(a[0]==‘0‘) 59 break; 60 int len=strlen(a); 61 ch[i][0]=a[0]; 62 ch[i][1]=a[len-1]; 63 } 64 k=i+1; 65 flag=0; 66 memset(vis,0,sizeof(vis)); 67 for(i=0;i<k;i++) 68 { 69 if(ch[i][0]==‘b‘) 70 { 71 dfs(i); 72 vis[i]=0; 73 } 74 } 75 printf("%s\n",flag?"Yes.":"No."); 76 } 77 return 0; 78 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5031229.html