BestCoder 1st Anniversary B.Hidden String DFS
B. Hidden String
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=610&pid=1002
Description
今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为n的字符串s. 他想要知道能否找到s的三个互不相交的子串s[l1..r1], s[l2..r2], s[l3..r3]满足下列条件: 1. 1≤l1≤r1<l2≤r2<l3≤r3≤n 2. s[l1..r1], s[l2..r2], s[l3..r3]依次连接之后得到字符串"anniversary".
Input
输入有多组数据. 第一行有一个整数T (1≤T≤100), 表示测试数据组数. 然后对于每组数据: 一行包含一个仅含小写字母的字符串s (1≤|s|≤100).
Output
对于每组数据, 如果Soda可以找到这样三个子串, 输出"YES", 否则输出"NO".
Sample Input
2
annivddfdersewwefary
nniversarya
Sample Output
YES
NO
HINT
题意
题解:
DFS
代码
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef __int64 ll;
using namespace std; typedef __int64 ll;
const int inf = (int)1E9+;
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
} //******************************* int T;
char s[];
char s1[] = "anniversary";
bool dfs(int num,int k,int i)
{
if(num >= ) return ;
while(s[k] != '\0')
{
if(s[k] == s1[i])
{
k++;
i++;
if(dfs(num+,k,i)) return true;
if(s1[i] == '\0')return true;
}
else
{
break;
}
}
for(; s[k] != '\0'; ++k)
{
if(s[k] == s1[i])
{
if(dfs(num+,k,i)) return true;
}
}
return false;
}
int main()
{
cin>>T;
while(T--)
{
scanf("%s",s);
int flag=;
for(int i=; s[i]!='\0'; ++i)
{
if(s[i]=='a')
{
flag=dfs(,i,);
if(flag) break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}
BestCoder 1st Anniversary B.Hidden String DFS的更多相关文章
- BestCoder 1st Anniversary ($) 1002.Hidden String
		Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ... 
- hdu 5311  Hidden String (BestCoder 1st Anniversary ($))(深搜)
		http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others) ... 
- 二分图点染色 BestCoder 1st Anniversary($) 1004 Bipartite Graph
		题目传送门 /* 二分图点染色:这题就是将点分成两个集合就可以了,点染色用dfs做, 剩下的点放到点少的集合里去 官方解答:首先二分图可以分成两类点X和Y, 完全二分图的边数就是|X|*|Y|.我们的 ... 
- BestCoder 1st Anniversary($) 1003 Sequence
		题目传送门 /* 官方题解: 这个题看上去是一个贪心, 但是这个贪心显然是错的. 事实上这道题目很简单, 先判断1个是否可以, 然后判断2个是否可以. 之后找到最小的k(k>2), 使得(m-k ... 
- BestCoder 1st Anniversary ——HDU5312(数学推导)
		Today, Soda has learned a sequence whose n-th (n≥1) item is 3n(n−1)+1. Now he wants to know if an in ... 
- BestCoder 1st Anniversary
		Souvenir Accepts: 1078 Submissions: 2366 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ... 
- BestCoder 1st Anniversary 1004 Bipartite Graph 【二分图 + bfs + 良好的逻辑思维 】
		题目地址:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=610&pid=1004 问题描述 Soda有一个$ ... 
- hdu 5310 Souvenir(BestCoder 1st Anniversary ($))
		http://acm.hdu.edu.cn/showproblem.php?pid=5310 题目大意:要买n个纪念品,可以单个买p元每个,可以成套买q元一套,每套有m个,求最少花费 #include ... 
- 【BestCoder 1st Anniversary】
		AB题都是签到题.... C 题意: 有一串数列,An=3*n*(n-1)+1 然后要从A数列中选取尽量少个数(可重复),使得Sum(An)=m 题解: 贪心地想,能拿大就拿大很明显就是错的...[哪 ... 
随机推荐
- afasf
			http://www.cnblogs.com/ttzhang/archive/2008/11/02/1324601.html project server 2007 sn :W2JJW-4KYDP-2 ... 
- IMEI是什么? 怎样查手机串号IMEI
			IMEI的基本含义 IMEI(International Mobile Equipment Identity,移动设备国际识别码,又称为国际移动设备标识)是手机的唯一识别号码.我们从这个缩写的全称中来 ... 
- C++中map的基本操作和使用;
			注:本文来自sina live 的博文 Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可以起到事半功倍的效果,总结了一些map基本简单实用的操作!1. map最基本 ... 
- lamp 网站打不开,不显示也不报错,
			原因是该网站的编程员,习惯简写,<? ?>;而服务器版本的php.ini 默认不支持只支持<?php ?>这种格式. 解决方法vim /usr/loacl/php/etc/ph ... 
- 繁华模拟赛 Evensgn的债务
			#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ... 
- Android 中this、 getApplicationContext()、getApplication()之间的区别
			this:代表当前,在Activity当中就是代表当前的Activity,换句话说就是Activity.this在Activity当中可以缩写为this. getApplicationContext( ... 
- Vim的使用方法
			导读 Vim是从vi发展出来的一个文本编辑器.代码补全.编译及错误跳转等方便编程的功能特别丰富,在程序员中被广泛使用,和Emacs并列成为类Unix系统用户最喜欢的文本编辑器. 一.vi.vim介绍 ... 
- HDOJ 1863 prim算法 HDOJ 1879
			#include<cstdio> #include<cstring> #define inf 0xffffff ][]; int ans; void prim(int n) { ... 
- python安装问题
			安装MinGW之后 出现.. 解决方案 ================ 
- Unique Binary Search Trees I & II
			Given n, how many structurally unique BSTs (binary search trees) that store values 1...n? Example Gi ... 
