标签:put family rip big order str border contest 一点
http://acm.hdu.edu.cn/showproblem.php?pid=1181
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 36929 Accepted Submission(s): 13091
//#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f3f3f #define mod 1000000007 #define PI acos(-1) using namespace std; typedef long long ll ; char s[1009] ; int vis[1009]; int flag ; int l ; struct node { char he , ba ; }a[1009]; void dfs(int d , int ans) { if(a[d].ba == ‘m‘ && ans != 0) { flag = 1 ; return ; } if(flag) return ; for(int i = 0 ; i < l ; i++) { if(a[d].ba == a[i].he && !vis[i]) { vis[i] = 1 ; dfs(i , ans+1); } } vis[d] = 0 ; } int main() { while(~scanf("%s" , s)) { if(strcmp(s , "0") == 0) continue ; memset(a , ‘\0‘ , sizeof(a)); memset(vis , 0 , sizeof(vis)); flag = 0; l = 0 ; int len = strlen(s); a[l].he = s[0]; a[l].ba = s[len-1]; l++ ; while(~scanf("%s" , s) && strcmp(s , "0")) { len = strlen(s); a[l].he = s[0]; a[l].ba = s[len-1]; l++; } for(int i = 0 ; i < l ; i++) { if(a[i].he == ‘b‘) { vis[i] = 1 ; dfs(i , 0); } } if(flag) cout << "Yes." << endl ; else cout << "No." << endl ; } return 0; }
标签:put family rip big order str border contest 一点
原文地址:https://www.cnblogs.com/nonames/p/11706275.html