dfs(首尾字母)
http://acm.hdu.edu.cn/showproblem.php?pid=1181
变形课
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 36929 Accepted Submission(s): 13091
Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的道理.
soon
river
goes
them
got
moon
begin
big
0
Hint
Harry 可以念这个咒语:"big-got-them".
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
char s[] ;
int vis[];
int flag ;
int l ; struct node
{
char he , ba ;
}a[]; void dfs(int d , int ans)
{
if(a[d].ba == 'm' && ans != )
{
flag = ;
return ;
}
if(flag)
return ;
for(int i = ; i < l ; i++)
{
if(a[d].ba == a[i].he && !vis[i])
{
vis[i] = ;
dfs(i , ans+);
}
}
vis[d] = ;
} int main()
{
while(~scanf("%s" , s))
{
if(strcmp(s , "") == )
continue ;
memset(a , '\0' , sizeof(a));
memset(vis , , sizeof(vis));
flag = ;
l = ;
int len = strlen(s);
a[l].he = s[];
a[l].ba = s[len-];
l++ ;
while(~scanf("%s" , s) && strcmp(s , ""))
{
len = strlen(s);
a[l].he = s[];
a[l].ba = s[len-];
l++;
} for(int i = ; i < l ; i++)
{
if(a[i].he == 'b')
{
vis[i] = ;
dfs(i , );
}
}
if(flag)
cout << "Yes." << endl ;
else
cout << "No." << endl ;
} return ;
}
dfs(首尾字母)的更多相关文章
- UVa 10129单词(欧拉回路)
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- [欧拉路径]Play on Words UVA10129
传送门: UVA - 10129 题目大意: 给定一些单词(可能会重复出现),判断单词是否能排成一个序列,前提是单词的最后一个字母与下一个单词的第一个字母相同.输出"The door c ...
- 洛谷P1127-词链
Problem 洛谷P1127-词链 Accept: 256 Submit: 1.3kTime Limit: 1000 mSec Memory Limit : 128MB Problem ...
- Catenyms POJ - 2337(单词+字典序输出路径)
题意: 就是给出几个单词 看能否组成欧拉回路或路径 当然还是让输出组成的最小字典序的路 解析: 还是把首尾字母看成点 把单词看成边 记录边就好了 这题让我对fleury输出最小字典序又加深了一些 ...
- 8.6 正睿暑期集训营 Day3
目录 2018.8.6 正睿暑期集训营 Day3 A 亵渎(DP) B 绕口令(KMP) C 最远点(LCT) 考试代码 A B C 2018.8.6 正睿暑期集训营 Day3 时间:5h(实际) 期 ...
- LeetCode刷题记录(python3)
由于之前对算法题接触不多,因此暂时只做easy和medium难度的题. 看完了<算法(第四版)>后重新开始刷LeetCode了,这次决定按topic来刷题,有一个大致的方向.有些题不止包含 ...
- UVA-10129 Play on Words (判断欧拉道路的存在性)
题目大意:给出一系列单词,当某个单词的首字母和前一个单词的尾字母相同,则这两个单词能链接起来.给出一系列单词,问是否能够连起来. 题目分析:以单词的首尾字母为点,单词为边建立有向图,便是判断图中是否存 ...
- HDU 2340 Obfuscation (暴力)
题意:给定一篇文章,将每个单词的首尾字母不变,中间顺序打乱,然后将单词之间的空格去掉,得到一个序列,给出一个这样的序列,给你一个字典,将原文翻译出来. 析:在比赛的时候读错题了,忘记首尾字母不变了,一 ...
- Codeforces 1131 (div 2)
链接:http://codeforces.com/contest/1131 A Sea Battle 利用良心出题人给出的图,不难看出答案为\(2*(h1+h2)+2*max(w1,w2)+4\)由于 ...
随机推荐
- Flutter-使用Dialog時出現No MaterialLocalizations found
在显示SimpleDialog时候程序报错 No MaterialLocalizations found 没有找到 MaterialLocalizations 搜索找到原因 runApp 需要先调用 ...
- 手动创建一个Spring Boot 2.x项目
spring boot 2.1.9版本quick start参考文档地址:https://docs.spring.io/spring-boot/docs/2.1.9.RELEASE/reference ...
- 自学semantic UI个人博客首页模板
以下是代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <m ...
- 8:Spring Boot中thymeleaf模板中使用 Shiro标签
1,添加 pom.xml grade: compile('com.github.theborakompanioni:thymeleaf-extras-shiro:1.2.1') 2, Subject ...
- Comet OJ - Contest #7 D 机器学习题 斜率优化 + 未调完
Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) f ...
- Apache启动错误:could not bind to address[::]:443
Q:Windows环境下启动apache报错如下: 可是在httpd.conf文件中apache listen的明明是http 80端口,为什么会报443的错误? A:因为你的计算机安装了VM,所有有 ...
- Packet Transactions: High-level Programming for Line-Rate Switches
Name of article:Packet Transactions: High-level Programming for Line-Rate Switches Origin of the art ...
- android 启动默认的邮件客户端,多附件的问题
目前开发的app中需要发送邮件,所以需要调用android默认的邮件客户端,并需要添加多个邮件附件,我该通过哪个组件调用默认的客户端?用什么组件来支持多个附件的电子邮件? 是通过下面的哪一个?(Int ...
- 大数据笔记(六)——HDFS的底层原理:JAVA动态代理和RPC
一.Java的动态代理对象 实现代码如下: 1.接口类MyService package hdfs.proxy; public interface MyService { public void me ...
- centos6.X mysql 5.1 主主配置
1.配置文件 A库的配置文件: 在 /etc/my.cnf [mysqld] 段 新增: server_id= # log_bin 日志路径.格式以及删除时间(30天) log_bin=/var/li ...