变形课

Problem Description

呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体.


Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的道理.

Input

测试数据有多组。每组有多行,每行一个单词,仅包括小写字母,是Harry所会的所有咒语.数字0表示一组输入结束.

Output

如果Harry可以完成他的作业,就输出"Yes.",否则就输出"No."(不要忽略了句号)

Sample Input

so
soon
river
goes
them
got
moon
begin
big
0

Sample Output

Yes.

Hint

Hint

Harry 可以念这个咒语:"big-got-them".

————————————————————————————————————————————

直接把每个单词头尾存一下遍历就好
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std; using namespace std;
const int maxn = 100000; char st[maxn], et[maxn];
int vis[maxn], t;
bool ok; void DFS(int x){
if (et[x] == 'm'){
ok = true; return;
}
for (int i = 0; i<t; ++i){
if (vis[i] || st[i] != et[x])
continue;
vis[i] = 1;
DFS(i);
vis[i] = 0;
if (ok)return;
}
} int main() {
char s[1000];
int k;
while (~scanf("%s",s))
{
t = 0;
while (s[0] != '0')
{
k = strlen(s);
st[t] = s[0];
et[t++] = s[k- 1];
scanf("%s", s);
}
memset(vis, 0, sizeof(vis));
ok = false;
for (int i = 0; i<t; ++i)
{
if (st[i] != 'b')
continue;
vis[i] = 1;
DFS(i);
}
if (ok)
printf("Yes.\n");
else printf("No.\n");
}
return 0;
}

HDU1181 变形课(DFS) 2016-07-24 13:31 73人阅读 评论(0) 收藏的更多相关文章

  1. 积分图像的应用(一):局部标准差 分类: 图像处理 Matlab 2015-06-06 13:31 137人阅读 评论(0) 收藏

    局部标准差在图像处理邻域具有广泛的应用,但是直接计算非常耗时,本文利用积分图像对局部标准差的计算进行加速. 局部标准差: 标准差定义如下(采用统计学中的定义,分母为): 其中. 为了计算图像的局部标准 ...

  2. HDU1426 Sudoku Killer(DFS暴力) 2016-07-24 14:56 65人阅读 评论(0) 收藏

    Sudoku Killer Problem Description 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会 ...

  3. HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏

    Red and Black Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  4. HDU1045 Fire Net(DFS枚举||二分图匹配) 2016-07-24 13:23 99人阅读 评论(0) 收藏

    Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...

  5. HDU2212 DFS 2016-07-24 13:52 56人阅读 评论(0) 收藏

    DFS Problem Description A DFS(digital factorial sum) number is found by summing the factorial of eve ...

  6. POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏

    A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...

  7. 百度地图-省市县联动加载地图 分类: Demo JavaScript 2015-04-26 13:08 530人阅读 评论(0) 收藏

    在平常项目中,我们会遇到这样的业务场景: 客户希望把自己的门店绘制在百度地图上,通过省.市.区的选择,然后加载不同区域下的店铺位置. 先看看效果图吧: 实现思路: 第一步:整理行政区域表: 要实现通过 ...

  8. 棋盘问题 分类: 搜索 POJ 2015-08-09 13:02 4人阅读 评论(0) 收藏

    棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28474 Accepted: 14084 Description 在一 ...

  9. Power Network 分类: POJ 2015-07-29 13:55 3人阅读 评论(0) 收藏

    Power Network Time Limit: 2000MS Memory Limit: 32768K Total Submissions: 24867 Accepted: 12958 Descr ...

随机推荐

  1. 设计模式学习笔记(1)Iterator

    Iterator 模式 public interface Iterator { public boolean hasNext(); public Object next(); } public int ...

  2. 文件和Variant的转换

    function FileToVariant(FileName: String): OleVariant; var   AStream: TFileStream;   MyBuffer: Pointe ...

  3. python的可变list和不可变tuple, dict和set

    list和tuple 在python中分为可变表和不可变表: 类型 名称 表示方法 可变 list [] 不可变 tuple () list list是可变表,list内部索引从0开始,正整数是正序的 ...

  4. ionic 2,带着运气成分

    npm config set loglevel info   查看安装信息 npm cache clean                  清除缓存 cnpm sync ionic         ...

  5. js中的变量提升(hoisting)

    来看如下代码: function HelloJS(){ var array = [1,2,3,4,5]; for(var i in array){ } alert(i); } HelloJS(); a ...

  6. np.identity()

    二.np.identity()这个函数和之前的区别在于,这个只能创建方阵,也就是N=M 函数的原型:np.identity(n,dtype=None) 参数:n,int型表示的是输出的矩阵的行数和列数 ...

  7. C# 发送电子邮件(含附件)用到的类 system.web.mail

    主要是用到了System.Web.Mail命名空间,用到了此空间的三个类,分别是: ●MailMessage类,用于构造电子邮件●MailAttachment类,用于构造电子邮件附件●SmtpMail ...

  8. Java动态代理机制详解(类加载,JDK 和CGLIB,Javassist,ASM)

    class文件简介及加载 Java编译器编译好Java文件之后,产生.class 文件在磁盘中.这种class文件是二进制文件,内容是只有JVM虚拟机能够识别的机器码.JVM虚拟机读取字节码文件,取出 ...

  9. Spring的2.5版本中提供了一种:p名称空间的注入(了解)

    1. 步骤一:需要先引入 p 名称空间 * 在schema的名称空间中加入该行:xmlns:p="http://www.springframework.org/schema/p"( ...

  10. Algorithmic Trading[z]

    Algorithmic Trading has been a hot topic for equity/derivative trading over a decade. Many ibanks an ...