搜索专题: HDU1501Zipper
Zipper
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10465 Accepted Submission(s): 3762
For example, consider forming "tcraete" from "cat" and "tree":
String A: cat
String B: tree
String C: tcraete
As you can see, we can form the third string by alternating characters from the two strings. As a second example, consider forming "catrtee" from "cat" and "tree":
String A: cat
String B: tree
String C: catrtee
Finally, notice that it is impossible to form "cttaree" from "cat" and "tree".
set per line.
For each data set, the line of input consists of three strings, separated by a single space. All strings are composed of upper and lower case letters only. The length of the third string is always the sum of the lengths of the first two strings. The first two
strings will have lengths between 1 and 200 characters, inclusive.
Data set n: yes
if the third string can be formed from the first two, or
Data set n: no
if it cannot. Of course n should be replaced by the data set number. See the sample output below for an example.
3
cat tree tcraete
cat tree catrtee
cat tree cttaree
Data set 1: yes
Data set 2: yes
Data set 3: no
RunId : 21249294 Language : G++ Author : hnustwanghe
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 200 + 5;
char a[N],b[N],c[2*N];
bool visit[N][N],can_find;
void DFS(int i,int j,int k){
if(can_find || visit[i][j]) return;
if(c[k]=='\0'){can_find = true;return;}
visit[i][j] = true;
if(a[i]!='\0' && a[i] == c[k])
DFS(i+1,j,k+1);
if(b[j]!='\0' && b[j] == c[k])
DFS(i,j+1,k+1);
}
int main(){
int T,cnt=0;
scanf("%d",&T);
while(T--){
scanf("%s %s %s",a,b,c);
memset(visit,0,sizeof(visit));
can_find = false;
DFS(0,0,0);
printf("Data set %d: %s\n",++cnt,can_find?"yes":"no");
}
return 0;
}
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 200 + 5;
char a[N],b[N],c[2*N];
bool visit[N][N],can_find; void DFS(int i,int j,int k){
if(can_find || visit[i][j]) return;
if(c[k]=='\0'){can_find = true;return;}
visit[i][j] = true;
if(a[i]!='\0' && a[i] == c[k])
DFS(i+1,j,k+1);
if(b[j]!='\0' && b[j] == c[k])
DFS(i,j+1,k+1);
}
int main(){
int T,cnt=0;
scanf("%d",&T);
while(T--){
scanf("%s %s %s",a,b,c);
memset(visit,0,sizeof(visit));
can_find = false;
DFS(0,0,0);
printf("Data set %d: %s\n",++cnt,can_find?"yes":"no");
}
return 0;
}
搜索专题: HDU1501Zipper的更多相关文章
- HDU(搜索专题) 1000 N皇后问题(深度优先搜索DFS)解题报告
前几天一直在忙一些事情,所以一直没来得及开始这个搜索专题的训练,今天做了下这个专题的第一题,皇后问题在我没有开始接受Axie的算法低强度训练前,就早有耳闻了,但一直不知道是什么类型的题目,今天一看,原 ...
- NOIP2018提高组金牌训练营——搜索专题
NOIP2018提高组金牌训练营——搜索专题 1416 两点 福克斯在玩一款手机解迷游戏,这个游戏叫做”两点”.基础级别的时候是在一个n×m单元上玩的.像这样: 每一个单元有包含一个有色点.我们将用不 ...
- 搜索专题:Balloons
搜索专题:Balloons 这道题一看与时间有关,第一想到的就是BFS,定义一个状态,包含每一个状态的剩余气球数,已经进行的时间和每一个志愿者上一次吹气球的时间: 每一次状态转换时,检查是否有没有使用 ...
- 2014 UESTC暑前集训搜索专题解题报告
A.解救小Q BFS.每次到达一个状态时看是否是在传送阵的一点上,是则传送到另一点即可. 代码: #include <iostream> #include <cstdio> # ...
- 【PHP高效搜索专题(2)】sphinx&coreseek在PHP程序中的应用实例
PHP可以通过三种途径来调用sphinx 通过Sphinx官方提供的API接口(接口有Python,Java,Php三种版本) 通过安装SphinxSE,然后创建一个中介sphinxSE类型的表,再通 ...
- 【PHP高效搜索专题(1)】sphinx&Coreseek的介绍与安装
我们已经知道mysql中带有"%keyword%"条件的sql是不走索引的,而不走索引的sql在大数据量+大并发量的时候,不仅效率极慢还很有可能让数据库崩溃.那我们如何通过某些关键 ...
- 2015 UESTC 搜索专题F题 Eight Puzzle 爆搜
Eight Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 ...
- 2015 UESTC 搜索专题B题 邱老师降临小行星 记忆化搜索
邱老师降临小行星 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/61 Des ...
- 蓝桥杯dfs搜索专题
2018激光样式 #include<bits/stdc++.h> using namespace std; /* dfs(i) 第i个激光机器 有两种选择:vis[i-1] == 0 时 ...
随机推荐
- ETL工具之——kettle使用简介
ETL工具之——kettle使用简介 https://yq.aliyun.com/articles/157977?spm=5176.10695662.1996646101.searchclickres ...
- 汇总apply()、call()、bind()用法详解
先看明白下面: 例 1 obj.objAge; // 17 obj.myFun() // 小张年龄 undefined 例 2 shows() // 盲僧 比较一下这两者 this 的差别,第一个打印 ...
- 基于STM32的CRC校验说明
///***************************************************************************** //下面是test.c里面的函数 // ...
- React Native中集成友盟社会化分享-----童叟无欺
1.下载所需的jar,下载地址https://developer.umeng.com/sdk/reactnative?spm=a211g2.211692.0.0.28967d238GW6mC 2.将以 ...
- BZOJ 4373: 算术天才⑨与等差数列 线段树
Description 算术天才⑨非常喜欢和等差数列玩耍. 有一天,他给了你一个长度为n的序列,其中第i个数为a[i]. 他想考考你,每次他会给出询问l,r,k,问区间[l,r]内的数从小到大排序后能 ...
- 聊聊 Vue 的双向数据绑定,Model 如何改变 View,View 又是如何改变 Model 的
todo defineProperty() 参考: https://www.cnblogs.com/wangjiachen666/p/9883916.html
- linux文件重定向
1:标准输出:2:错误输出 1,exec启动一个新的shell将STDOUT文件描述符重定向到文件 #!/bin/shecho "test exec..."exec > ou ...
- Pyhton实用的format()格式化函数
Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 : 来代替以前的 % . format 函数可以接受不限个参数 ...
- Controller控制台Vuser虚拟用户的运行状态
Controller控制台Vuser运行的状态 Down:没有运行Pending:挂起Init:初始化Ready:准备就绪Run:正在运行Rendezvous:正在集结Passed:运行通过Faile ...
- python jieba分词(结巴分词)、提取词,加载词,修改词频,定义词库 -转载
转载请注明出处 “结巴”中文分词:做最好的 Python 中文分词组件,分词模块jieba,它是python比较好用的分词模块, 支持中文简体,繁体分词,还支持自定义词库. jieba的分词,提取关 ...