HDOJ  1181    变形课
2015-12-18 18:07
531 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1181
#include<iostream>
#include <cstdio>
#include<cstring>
using namespace std;
struct
{
char
beg;
char
end;
}M[101];
bool hash[101],f;
int N;
bool DFS(char ch)
{
if(ch =='m')
{
f= rue;
return true;
}
for(int i = 0;i<N;++i)
if(M[i].beg==ch&&!hash[i])
{
hash[i] = true;
DFS ( M[i].end );
hash[i] = false;
}
return false;
}
int main ()
{
string
str;
while (cin
>>str)
{
N = 0;
f = false;
memset ( hash, 0 , sizeof ( hash ) );
while ( str != "0" )
{
M
.beg = str[0];
M
.end = str[ str.size() - 1 ];
N++;
cin >> str;
}
DFS ( 'b' );
puts ( f ? "Yes." : "No." );
}
return
0;
}
#include<iostream>
#include <cstdio>
#include<cstring>
using namespace std;
struct
{
char
beg;
char
end;
}M[101];
bool hash[101],f;
int N;
bool DFS(char ch)
{
if(ch =='m')
{
f= rue;
return true;
}
for(int i = 0;i<N;++i)
if(M[i].beg==ch&&!hash[i])
{
hash[i] = true;
DFS ( M[i].end );
hash[i] = false;
}
return false;
}
int main ()
{
string
str;
while (cin
>>str)
{
N = 0;
f = false;
memset ( hash, 0 , sizeof ( hash ) );
while ( str != "0" )
{
M
.beg = str[0];
M
.end = str[ str.size() - 1 ];
N++;
cin >> str;
}
DFS ( 'b' );
puts ( f ? "Yes." : "No." );
}
return
0;
}
相关文章推荐
- 韦东山第三期视频监控wpa_supplicant编译出错问题
- Android图片裁剪开源组件 实现了图片翻转,裁剪
- 使用Android Studio新建项目
- 关于android进程间通信(handler、messenger、AIDL)
- package.json依赖管理dependencies中 ^ 和 ~ 的区别
- HDOJ&nbsp;1350&nbsp;&nbsp;&nbsp;&nbsp;Robot&nbsp;Motion
- HDOJ&nbsp;&nbsp;1722&nbsp;&nbsp;&nbsp;&nbsp;Cake
- HDOJ&nbsp;&nbsp;1271&nbsp;&nbsp;&nbsp;整数对
- HDOJ&nbsp;&nbsp;&nbsp;1021&nbsp;&nbsp;&nbsp;&nbsp;Fibonacci&nbsp;Again
- Fibonacci数列
- HDOJ&nbsp;&nbsp;1010&nbsp;&nbsp;&nbsp;Tempter&nbsp;of&nbsp;the&nbsp;Bone
- HDOJ&nbsp;&nbsp;1005&nbsp;&nbsp;&nbsp;Number&nbsp;Sequence
- HDOJ&nbsp;&nbsp;1040&nbsp;&nbsp;As&nbsp;Easy&nbsp;As&nbsp;A+B
- 欧拉φ函数
- C语言中的qsort函数
- C++中的sort函数
- HDOJ&nbsp;2673&nbsp;sh&#462;崽&nbsp;OrOrOrOrz
- HDOJ&nbsp;2037&nbsp;今年暑假不AC
- HDOJ&nbsp;1753&nbsp;大明A+B
- HDOJ&nbsp;1236&nbsp;排名