HDU 5311:Hidden String
Hidden String
今天是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".
输入有多组数据. 第一行有一个整数T (1≤T≤100), 表示测试数据组数. 然后对于每组数据: 一行包含一个仅含小写字母的字符串s (1≤|s|≤100).
对于每组数据, 如果Soda可以找到这样三个子串, 输出"YES", 否则输出"NO".
2
annivddfdersewwefary
nniversarya
YES
NO
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; vector<int> wei_z[30];
vector<int> weizhi;
char test[200];
int len,i,flag; void init()
{
for(i=0;i<len;i++)
{
wei_z[test[i]-'a'].push_back(i);
}
} bool pend()
{
int result=0,temp=weizhi[0];
for(i=1;i<weizhi.size();i++)
{
if(temp!=weizhi[i]-1)
result++;
temp=weizhi[i];
}
if(result<=2)
return true;
else
return false;
} void solve()
{
int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10,i11;
for(i1=0;i1<wei_z['a'-'a'].size();i1++)
{
for(i2=0;i2<wei_z['n'-'a'].size();i2++)
{
if(wei_z['n'-'a'][i2]<=wei_z['a'-'a'][i1])continue;
for(i3=0;i3<wei_z['n'-'a'].size();i3++)
{
if(wei_z['n'-'a'][i3]<=wei_z['n'-'a'][i2])continue;
for(i4=0;i4<wei_z['i'-'a'].size();i4++)
{
if(wei_z['i'-'a'][i4]<=wei_z['n'-'a'][i3])continue;
for(i5=0;i5<wei_z['v'-'a'].size();i5++)
{
if(wei_z['v'-'a'][i5]<=wei_z['i'-'a'][i4])continue;
for(i6=0;i6<wei_z['e'-'a'].size();i6++)
{
if(wei_z['e'-'a'][i6]<=wei_z['v'-'a'][i5])continue;
for(i7=0;i7<wei_z['r'-'a'].size();i7++)
{
if(wei_z['r'-'a'][i7]<=wei_z['e'-'a'][i6])continue;
for(i8=0;i8<wei_z['s'-'a'].size();i8++)
{
if(wei_z['s'-'a'][i8]<=wei_z['r'-'a'][i7])continue;
for(i9=0;i9<wei_z['a'-'a'].size();i9++)
{
if(wei_z['a'-'a'][i9]<=wei_z['s'-'a'][i8])continue;
for(i10=0;i10<wei_z['r'-'a'].size();i10++)
{
if(wei_z['r'-'a'][i10]<=wei_z['a'-'a'][i9])continue;
for(i11=0;i11<wei_z['y'-'a'].size();i11++)
{
if(wei_z['y'-'a'][i11]<=wei_z['r'-'a'][i10])continue;
weizhi.push_back(wei_z['a'-'a'][i1]);
weizhi.push_back(wei_z['n'-'a'][i2]);
weizhi.push_back(wei_z['n'-'a'][i3]);
weizhi.push_back(wei_z['i'-'a'][i4]);
weizhi.push_back(wei_z['v'-'a'][i5]);
weizhi.push_back(wei_z['e'-'a'][i6]);
weizhi.push_back(wei_z['r'-'a'][i7]);
weizhi.push_back(wei_z['s'-'a'][i8]);
weizhi.push_back(wei_z['a'-'a'][i9]);
weizhi.push_back(wei_z['r'-'a'][i10]);
weizhi.push_back(wei_z['y'-'a'][i11]);
if(pend()==true)
{
flag=1;
return;
}
weizhi.clear();
}
}
}
}
}
}
}
}
}
}
}
} int main()
{
int Test1;
cin>>Test1; while(Test1--)
{
cin>>test;
for(i=0;i<=29;i++)
wei_z[i].clear();
weizhi.clear();
flag=0;
len=strlen(test);
init();
solve();
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 5311:Hidden String的更多相关文章
- HDU 4055:Number String(DP计数)
http://acm.hdu.edu.cn/showproblem.php?pid=4055 题意:给一个仅包含‘I','D','?'的字符串,’I'表示前面的数字比后面的数字要小(Increase升 ...
- 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) ...
- HDU 5311 Hidden String (优美的暴力)
Hidden String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- hdu 5311 Hidden String
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Description Today is the 1st anniv ...
- BestCoder 1st Anniversary B.Hidden String DFS
B. Hidden String Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contests/co ...
- BestCoder 1st Anniversary ($) 1002.Hidden String
Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 26 ...
- HDU 5842 Lweb and String(Lweb与字符串)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋)
HDU 2594 Simpsons’ Hidden Talents(辛普森一家的潜在天赋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 3 ...
- hdu 4850 Wow! Such String! 欧拉回路
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...
随机推荐
- Redis Cluster 强制kill某一个节点和shutdown某一个节点后修复过程
redis cluster 命令行,执行以下命令需登录cluster,是集群所独有的集群(cluster)CLUSTER INFO 打印集群的信息CLUSTER NODES 列出集群当前已知的所有节点 ...
- 二叉树 - DFS与BFS
二叉树 - DFS与BFS 深度优先遍历 (DFS Depth First Search) 就是一个节点不到头(叶子节点为空) 不回头 广度有点遍历(BFS Breadth First Sea ...
- Day4 - D - Watchcow POJ - 2230
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the ...
- 048、Java中使用switch判断
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- Java基础学习总结(二)
Java语言的特点: Java语言是简单的 Java语言是面向对象的 Java语言是跨平台(操作系统)的(即一次编写,到处运行) Java是高性能的 运行Java程序要安装和配置JDK jdk是什么? ...
- SNOI2019 选做
施工中... d1t1 字符串 题面 考虑两个字符串 \(s_i,s_j(i<j)\) ,实质是 \(s[i+1,\dots j]\) 和 \(s[i,\dots ,j-1]\) 的字符串字典序 ...
- mysql 分组查询入门
- mysql 模糊查询中包含特殊字符查询
- HihoCoder第十四周:无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息--额,说远了,总之,小Hi和小H ...
- SpringBoot#InitBinder
__震惊!!我的天啦,OMG!! 1. initBinder对我而言的价值在于,通过传统表单post数据到后端的controller时候,数据类型的自动转换.比如前端页面填写一个日期字符串,通过Ini ...