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\)由于 ...
随机推荐
- expect自动远程拷贝脚本
expect自动远程拷贝脚本,利用rsync命令,脚本内容如下: #!/usr/bin/expect -- proc Usage_Exit {self} { puts "" put ...
- 多个excel文件内容合并到一个excel文件的多个sheet的小程序
# -*- coding:utf-8 -*- import xlrd, xlsxwriter # 待合并excelallxls = ["D:\\excelcs\\***.xlsx" ...
- unittest----skip(跳过用例)
我们在执行测试用例时,有时有些用例时不需要执行的,这时就需要用到unittest给我们提供的跳过用例的方法 @unittest.skip(reason):强制跳过,不需要判断条件.reason是跳过原 ...
- vue props父组件与子组件传值方法
/~~父组件 runshow.vue~~/ <template> <div> <conditions :fenxiConditonsList="propCond ...
- JS循环结构
什么是循环结构? 反复一遍又一遍做着相同(相似)的事情 循环结构的两大要素? 循环条件:什么时候开始,什么时候结束 循环操作:循环体,循环过程中 做了什么 一.while语句 while语句 属于前测 ...
- adb打开系统设置的命令
adb命令打开手机设置页面 设置主页面adb shell am start com.android.settings/com.android.settings.Settings 安全adb shell ...
- php array_pop()函数 语法
php array_pop()函数 语法 作用:删除数组中的最后一个元素.博智达 语法:array_pop(array) 参数: 参数 描述 array 必需.规定数组. 说明:返回数组的最后 ...
- 国内npm镜像使用方法
npm全称Node Package Manager,是node.js的模块依赖管理工具.由于npm的源在国外,所以国内用户使用起来各种不方便.下面整理出了一部分国内优秀的npm镜像资源,国内用户可以选 ...
- 从Mybatis中#和$的区别到SQL预编译
#和$的区别 Mybatis中参数传递可以通过#和$设置.它们的区别是什么呢? # Mybatis在解析SQL语句时,sql语句中的参数会被预编译为占位符问号? $ Mybatis在解析SQL语句时, ...
- ORACLE 根据sql_id查询绑定变量的传入值
当前查询: select b.NAME, b.POSITION, b.DATATYPE_STRING, b.VALUE_STRING, b.LAST_CAPTURED from v$sql_bind_ ...