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\)由于 ...
随机推荐
- AGC014做题记录
貌似是比较水的一场 可是我依然8会做 C 发现除了第一步以外的走法都不会受到锁的影响并且一定选四个方向距离最近的径直走过去 那么第一步能走到的联通块取个min就好了 (我竟然第一发特别认真的写了一个D ...
- 如何用git将本地代码上传github
其实去年就用github了,但是毕竟也只是在上面搜索一些工作的难点和自我学习,自己都没有贡献过代码,觉得确实很low,知道今天自己用了2周左右的时间开发了 微信小程序,有了自己的贡献代码,所以想上传到 ...
- POJ2942 UVA1364 Knights of the Round Table 圆桌骑士
POJ2942 洛谷UVA1364(博主没有翻墙uva实在是太慢了) 以骑士为结点建立无向图,两个骑士间存在边表示两个骑士可以相邻(用邻接矩阵存图,初始化全为1,读入一对憎恨关系就删去一条边即可),则 ...
- 【leetcode】1143. Longest Common Subsequence
题目如下: Given two strings text1 and text2, return the length of their longest common subsequence. A su ...
- C#项目类型分三种,Dos(控制台),c/s(客户端与服务器),b/s(浏览器/服务器)
- makefile 打印
$(warning ----------$(abc)) $(info -----------------$(abc))
- HDU - 6578 Blank DP + 滚动数组
HDU - 6578 Blank 题意 给你\(\{0,1,2, 3\}\)四个数,分别填入长度为\(n\)的数列中,有\(m\)个限制条件,\(l_{i}, r_{i}, x_{i}\)表示在\([ ...
- linux ubantu php composer安装
root@iZwz93telmwbh624e5zetqZ:~# php -v PHP 5.6.40-14+ubuntu16.04.1+deb.sury.org+1 (cli) Copyright (c ...
- Internet History, Technology, and Security(week8)——Security: Encrypting and Signing
Hiding Date from Ohters Security Introduction Alice and Bob是密码学.博弈论.物理学等领域中的通用角色之一.Alice(代表A)和Bob(代表 ...
- (10)python学习笔记一
学习参考博客:http://blog.csdn.net/a359680405/article/details/42486689 深表感谢 1.单行注释 # 多行注释 "" ...