HDOJ1181(简单DFS)(练习使用STL)
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int MAX_N=;
vector<string> words;
map<string, bool> vis;
queue<string> que;
bool dfs(int i,string word)
{
int len=word.length();
if(word[len-]=='m')
{
return true;
}
if(i==words.size())
{
return false;
} for(int j=; j<words.size(); j++)
{
string s=words[j];
if(!vis[s]&&word[len-]==s[])
{
vis[s]=true;
if(dfs(i+,s))
return true;
vis[s]=false;
}
}
return false;
} void Judge()
{
bool flag=false; while(que.size()!=)
{
map<string,bool>::iterator it;
for(it=vis.begin(); it!=vis.end(); it++)
{
it->second=false;
}
string s=que.front();
que.pop();
vis[s]=true;
if(dfs(,s))
{
flag=true;
break;
}
} while(!que.empty())
{
que.pop();
}
if(flag)
{
printf("Yes.\n");
}
else
{
printf("No.\n");
}
}
int main()
{
string s;
while(cin>>s)
{
if(s.compare("")==)
{
Judge();
words.clear();
vis.clear();
continue;
}
words.push_back(s);
if(s[]=='b')
{
que.push(s);
}
} return ;
}
HDOJ1181(简单DFS)(练习使用STL)的更多相关文章
- Red and Black(简单dfs)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1979 Red and Black (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- POJ1573(Robot Motion)--简单模拟+简单dfs
题目在这里 题意 : 问你按照图中所给的提示走,多少步能走出来??? 其实只要根据这个提示走下去就行了.模拟每一步就OK,因为下一步的操作和上一步一样,所以简单dfs.如果出现loop状态,只要记忆每 ...
- POJ1979 Red and Black (简单DFS)
POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- CF760 C. Pavel and barbecue 简单DFS
LINK 题意:给出n个数,\(a_i\)代表下一步会移动到第\(a_i\)个位置,并继续进行操作,\(b_i\)1代表进行一次翻面操作,要求不管以哪个位置上开始,最后都能满足 1.到达过所有位置 2 ...
- uva 784 Maze Exploration(简单dfs)
这道题看上去非常麻烦,什么迷宫啊.门之类的,事实上挺简单的,就是让把与 * 连通的都置为 # 包含 * , 直接dfs就能够了,只是我wa了好多次...最后居然是多读了一个换行.忘了加getchar( ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
- BZOJ3991 [SDOI2015]寻宝游戏 【dfs序 + lca + STL】
题目 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩家可以任意选择一个村庄,瞬间转移到这个村庄,然后可以任意在地图的道路 ...
- 题解报告:hdu 1312 Red and Black(简单dfs)
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
随机推荐
- TRansportation ANalysis and SIMulation System
https://www.fhwa.dot.gov/planning/tmip/transims/background.cfm?from=groupmessage
- ORM性能相关
model: 先给一个简单的表结构 from django.db import models class User(models.Model): username=models.CharField(m ...
- pip-grep
Pip-pop pip-grep主要是用于方便查看Requirements.txt中那些模块是安装了的.也就是通过输入的然后模块名称然后在Requirements.txt中进行查询.里面比较难的就是d ...
- mysql怎么在已建好的表中添加自增序列
alter table 表明 change id id int not null auto_increment unique;
- sprintf在51单片机中的使用
sprintf在51单片机中的使用 unsigned char ch20_str[4]; unsigned char ch2o_m_str[6]; ch2o = 123; ch2o_m = 23456 ...
- PAT 天梯赛 L2-014. 列车调度 【队列】
题目链接 https://www.patest.cn/contests/gplt/L2-014 思路 其实 每条火车道 都可以视为一个队列 满足队列的性质 当已经存在的队列 中 的列车序号 都小于 当 ...
- UITableViewCell高度自适应的关键点
iOS开发中对于UITableViewCell高度自适应的文章已经很多很多,但如果cell内容比较复杂,刚使用autolayout配置自使用时还是总不能一次性成功. KEY POINT 这里只说设置的 ...
- [转]eclipse中的常用快捷键
1.选中你要加注释的区域,用ctrl+shift+C 会加上//注释2.先把你要注释的东西选中,用shit+ctrl+/ 会加上注释3.要修改在eclispe中的命令的快捷键方式我们只需进入windo ...
- Eclipse输入命令行参数
想要在Eclipse中输入命令行参数,可以在目录中该程序上右键,选择“Run As",选择”Run configurations",如图: 然后输入命令行参数: 点击Apply和R ...
- sqoop job从创建到执行
在学习sqoop job之前,最好先学习一下sqoop命令的导入导出 sqoop 使用 import 将 mysql 中数据导入到 hive sqoop 使用 import 将 mysql 中数据导入 ...