BestCoder 1st Anniversary ($) 1002.Hidden String

Hidden String

Accepts: 437

Submissions: 2174

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 262144/262144 K (Java/Others)

问题描写叙述

今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为的字符串. 他想要知道是否能找到的三个互不相交的子串, , 满足下列条件:

  1. 

  2. , , 依次连接之后得到字符串"anniversary".

输入描写叙述

输入有多组数据. 第一行有一个整数 , 表示測试数据组数. 然后对于每组数据:

一行包括一个仅含小写字母的字符串 .

输出描写叙述

对于每组数据, 假设Soda能够找到这样三个子串, 输出"YES", 否则输出"NO".

输入例子

2
annivddfdersewwefary
nniversarya

输出例子

YES
NO

分析:对“anniversary“进行分段,然后暴力查找就可以。

题目链接:http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=610&pid=1002

代码清单:

#include<queue>
#include<stack>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int get_index(string ss,string s,int p){ //暴力查找
    int slen=s.size();
    int sslen=ss.size();

    for(int i=p;i<=slen-sslen;i++){
        int first=1;
        for(int j=0;j<sslen;j++){
            if(ss[j]==s[i+j])
                continue;
            else{
                first=0;
                break;
            }
        }
        if(first){ return i+sslen; }
    }return -1;
}

bool judge(string s1,string s2,string s3,string s){
    int pp=get_index(s1,s,0);
    if(pp==-1) return false;
    pp=get_index(s2,s,pp);
    if(pp==-1) return false;
    pp=get_index(s3,s,pp);
    if(pp==-1) return false;
    return true;
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        string s;
        string str="anniversary";
        cin>>s;
        string s1="",s2,s3;
        bool ok=false;
        for(int i=1;i<=9;i++){ //分段
            s1+=str[i-1];
            for(int j=i;j<=9;j++){
                s2="";s3="";
                for(int k=i;k<=j;k++) s2+=str[k];
                for(int k=j+1;k<11;k++) s3+=str[k];
                if(judge(s1,s2,s3,s)){
                    ok=true;
                    break;
                }
            }if(ok) break;
        }
        if(ok) printf("YES\n");
        else printf("NO\n");
    }return 0;
}

时间: 2025-01-01 20:45:00

BestCoder 1st Anniversary ($) 1002.Hidden String的相关文章

BestCoder 1st Anniversary

problem 1001 Souvenir Accepts: 901 Submissions: 2743 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda想要给每个参赛者准备一个纪念品. 商店里纪念品的单价是p元, 同时也可以花q元购买纪念品套装, 一个套装里有mm个纪念品. 今天总共有nn个参赛者, Soda想

HDU 5312 Sequence(三角形数应用)——BestCoder 1st Anniversary ($)

传送门 Sequence Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1424    Accepted Submission(s): 442 Problem Description Today, Soda has learned a sequence whose n-th (n≥1) item is 3n(n?1)+1. Now

BestCoder 1st Anniversary 1002-1005

1002 Hidden String 这个题怎么暴力怎么搞就好了. 可以枚举最长匹配前缀, 和最长匹配后缀, 中间暴力for. 1 /*Author :usedrose */ 2 /*Created Time :2015/7/25 19:05:28*/ 3 /*File Name :2.cpp*/ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <sstream

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)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 1499    Accepted Submission(s): 534 Problem Description Today is the 1st anniversar

BestCoder 1st Anniversary--1001,1002解题

Souvenir Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 713    Accepted Submission(s): 436 Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, wants to

(BC 一周年)hdu 5311 Hidden String

Hidden String Accepts: 437 Submissions: 2174 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 今天是BestCoder一周年纪念日. 比赛管理员Soda有一个长度为nn的字符串ss. 他想要知道能否找到ss的三个互不相交的子串s[l_1..r_1]s[l?1??..r?1??], s[l_2..r_2]s[l?2??..r?2

HDU 5310 Hidden String(暴力枚举)

Hidden String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 429    Accepted Submission(s): 161 Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets

HDU 5311 Hidden String (优美的暴力)

Hidden String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 52    Accepted Submission(s): 25 Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a

Hidden String(判断正多边形)

Hidden String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1680    Accepted Submission(s): 592 Problem Description Today is the 1st anniversary of BestCoder. Soda, the contest manager, get