HDOJ1181变形记 DFS
2016-06-11 13:00
281 查看
这操蛋的输入格式。。。。貌似只要过第一组数据就行了。多组测试我答案是有错的。
这个代码可以ac。。。
这个是改完的
#include <iostream>
#include"sstream"
#include"string"
#include"algorithm"
#include"cstring"
#include"cstdio"
using namespace std;
struct se
{
char s;
char e;
se(){}
}str[1000];
int n;
int escape;
int visit[1000];
void dfs(char c)
{
int i;
if(escape) return ;
if(c=='m') {escape=1;return;}
for(i=0;i<n;i++)
if(str[i].s==c&&!visit[i])
{
visit[i]=1;
dfs(str[i].e);
}
}
int main()
{
string a;
int i=0;
while(cin>>a)
{
if(a!="0")
{
str[i].s=a[0];
str[i].e=a[a.size()-1];
i++;
memset(visit,0,sizeof(0));
}
else
{
n=i;
escape=0;
dfs('b');
if(escape) cout<<"Yes."<<endl;
else cout<<"No."<<endl;
}
}
return 0;
}
这个代码可以ac。。。
#include <iostream> #include"sstream" #include"string" #include"algorithm" #include"cstring" #include"cstdio" using namespace std; struct se { char s; char e; se(){} }str[1000]; int n; int escape; int visit[1000]; void dfs(char c) { int i; if(escape) return ; if(c=='m') {escape=1;return;} for(i=0;i<n;i++) if(str[i].s==c&&!visit[i]) { visit[i]=1; dfs(str[i].e); } } int main() { memset(visit,0,sizeof(visit)); string a; int i=0; while(cin>>a) { if(a!="0") { str[i].s=a[0]; str[i].e=a[a.size()-1]; i++; } else { n=i; escape=0; dfs('b'); if(escape) cout<<"Yes."<<endl; else cout<<"No."<<endl; } } return 0; }
这个是改完的
#include <iostream>
#include"sstream"
#include"string"
#include"algorithm"
#include"cstring"
#include"cstdio"
using namespace std;
struct se
{
char s;
char e;
se(){}
}str[1000];
int n;
int escape;
int visit[1000];
void dfs(char c)
{
int i;
if(escape) return ;
if(c=='m') {escape=1;return;}
for(i=0;i<n;i++)
if(str[i].s==c&&!visit[i])
{
visit[i]=1;
dfs(str[i].e);
}
}
int main()
{
string a;
int i=0;
while(cin>>a)
{
if(a!="0")
{
str[i].s=a[0];
str[i].e=a[a.size()-1];
i++;
memset(visit,0,sizeof(0));
}
else
{
n=i;
escape=0;
dfs('b');
if(escape) cout<<"Yes."<<endl;
else cout<<"No."<<endl;
}
}
return 0;
}
相关文章推荐
- AS的 Google App Indexing导致项目报错的方法
- scala 初始化
- 一般调试器工作原理
- 【行为型】Iterator模式
- xcode 自定义include路径
- Android调用微信扫一扫
- spark 启动
- 面向对象——final
- C++ c++与C语言的区别(三目运算符,const修饰符)
- FindJpg(2)-BitMap的高效加载和缓存
- android日常开发总结的技术经验60条
- 聊聊Linux动态链接中的PLT和GOT(1)——何谓PLT与GOT
- ubuntu12.04卸载wine
- 第十六周项目二 小玩文件(1)
- R Programming Assignment 1
- 一、设计模式概述
- 【CSS笔记六】CSS盒模型
- 关于炉石的奥弹打死精灵龙的分析
- 【OS】磁盘调度算法
- 计算农历24节气