首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HDUOJ----1181 变形课

HDUOJ----1181 变形课

作者头像
Gxjun
发布2018-03-21 13:15:31
5260
发布2018-03-21 13:15:31
举报
文章被收录于专栏:mlml

变形课

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 10665    Accepted Submission(s): 3972

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".

Source

Gardon-DYGG Contest 1

宽度搜索

代码如下:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstdlib>
 4 #include<iostream>
 5 #include<queue>
 6 using namespace std;
 7 const int maxn=10000;
 8 struct nod 
 9 {
10  char st,en;
11 };
12 nod str[maxn+5];
13 bool bfs(int pos ,int step)
14 {
15     queue<nod>cir;
16     nod temp;
17     int i;
18     cir.push(str[pos]);
19     while(!cir.empty())
20     {
21         temp=cir.front();
22         cir.pop();
23         for(i=0;i<step;i++)
24         {
25            if(temp.en=='m')
26             return true;
27            if(temp.en==str[i].st)
28            {
29                if(str[i].en=='m')
30                {
31                    return true;
32                }
33                /*入队*/
34               if(str[i].st=='b'||str[i].en=='b'||str[i].st==str[i].en)
35                    /*不许入队*/ ;
36               else
37                 {
38                   cir.push(str[i]);
39                   str[i].en='0';
40                   str[i].st='0';
41               }
42            }
43         }
44     }
45 return false;
46 }
47 int main()
48 {
49     char s[100];
50     int step=0,i;
51     while(scanf("%s",s)!=EOF)
52     {
53       /*输出结果*/
54     if(*s=='0')
55     {
56      bool tag=false;
57      for(i=0;i<step;i++)
58      {
59          if(str[i].st=='b')
60          {
61              if(bfs(i,step))
62              {         
63                  tag=true;
64                  break;
65              }
66          }
67      }
68      puts(tag?"Yes.":"No.");
69       step=0;
70       memset(str,'0',sizeof(str));
71     }
72     else
73     {
74         str[step].st=*s;
75         str[step++].en=s[strlen(s)-1];
76     }
77 
78     }
79     return 0;
80 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2013-11-09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 变形课
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档