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! 欧拉回 ...
随机推荐
- mysql 安装完以后没有mysql服务
用管理员身份打开命令控制台(cmd),然后将mysql的安装文件的路径打开(bin文件的路径),然后再路径下打上mysqld.exe -install, 会出现提示 Service successf ...
- springboot整合quartz并持久化到数据库
首先,这里的持久化是是如果当服务器宕机时,任务还在为我们保存.并且在启动服务器之后仍然可以自动执行 一.创建quartz 建表语句mysql的,quartz 2.3.0版本 DROP TABLE IF ...
- 使用命令行连接远程DB2数据库
1. 打开命令窗口 win + r 输入 db2cmd 2. 首先在客户机上对远程节点进行编目 CATALOG TCPIP //编目一个TCP/IP节点NOD ...
- GoJS最简单的实例
复制如下内容保存到空白的.html文件中,用浏览器打开即可查看效果 <!DOCTYPE html> <html> <head> <meta charset=& ...
- [笔记]ul>li>a做分布时, 让其居中显示效果
结构: <div id="page"> <ul> <li><a href="#">首页</a>< ...
- SQL添加列、非空、默认值
use MarcoBarcode go alter table [dbo].[WorkOrderRepairSheet] ADD needRepair int go ALTER TABLE [dbo] ...
- delphi日期GMT格式
function TForm1.DateTimeToGMT(const DateTime: TDateTime): string;const WEEK: array[1..7] of PChar = ...
- C++ Socket WSAENOBUFS WSAoverlapped
WSARecv的时候,投递的接收缓冲区的大小设置为0. 然后手动调用非阻塞recv从缓冲区接受数据,直到WSAEWOULDBLOCK,不然会有很多的buffer被锁住,当客户端的数量达到一定数目时,就 ...
- xv6 锁
在xv6 中锁对象是 spinlock,spinlock中的locked为1的时候表示被占用,为0的时候锁空闲. struct spinlock { uint locked; // Is the lo ...
- 自己安装windows版本的Flink
参照 https://blog.csdn.net/clj198606061111/article/details/99694033 我自己做一遍 找到对应的网址 https://flink.apach ...