HDU-5311

Hidden String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 368    Accepted Submission(s): 143

Problem Description

Today is the 1st anniversary of BestCoder. Soda, the contest manager, gets a string s of length n. He wants to find three nonoverlapping substrings s[l1..r1], s[l2..r2], s[l3..r3] that:

1. 1≤l1≤r1<l2≤r2<l3≤r3≤n

2. The concatenation of s[l1..r1], s[l2..r2], s[l3..r3] is "anniversary".

Input

There are multiple test cases. The first line of input contains an integer T (1≤T≤100), indicating the number of test cases. For each test case:

There‘s a line containing a string s (1≤|s|≤100) consisting of lowercase English letters.

Output

For each test case, output "YES" (without the quotes) if Soda can find such thress substrings, otherwise output "NO" (without the quotes).

Sample Input

2
annivddfdersewwefary
nniversarya

Sample Output

YES
NO

Source

BestCoder 1st Anniversary ($)

/**
    题意:给你一个串,看是否存在“anniversary”,并且是分成三段的
    做法:暴力
**/
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
#define maxn 1010 + 10
using namespace std;
char c[120] = {"anniversary"};
__int64 index = 0;
char ch[maxn];
int solve(int tt,int len)
{
    __int64 res = 0;
    __int64 mmax = 0;
    __int64 tmp = 0;
    for(int i=tt;i<len;i++)
    {
        if(ch[i] == c[index])
        {
            int j;
            res = 0;
            for(j=0;;j++)
            {
                if(ch[i+j] == c[index+j] && i+j<len)
                {
                    res++;
                }
                else
                    break;
            }
            if(res > mmax)
            {
                mmax = res;
                tmp = i + mmax;
            }
        }
    }
    index += mmax;
    return tmp;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        index = 0;
        scanf("%s",ch);
        __int64 len = strlen(ch);
        __int64 tt = 0;
        tt = solve(0,len);
        if(strcmp(ch,c) == 0)
        {
            printf("YES\n");
            continue;
        }
        if(tt == 0)
        {
            printf("NO\n");
            continue;
        }
        else if(index == 11)
        {
            printf("YES\n");
            continue;
        }
        tt = solve(tt,len);
        if(tt == 0)
        {
            printf("NO\n");
            continue;
        }
        else if(index == 11)
        {
            printf("YES\n");
            continue;
        }
        tt = solve(tt,len);
        if(tt == 0)
        {
            printf("NO\n");
            continue;
        }
        if(index == 11) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

Recommend

时间: 2024-10-04 18:56:47

HDU-5311的相关文章

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

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

(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 5311 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". 思路:其实就是要在一个串中找可能存在的3个连续子串来构成这个"anniversary&q

hdu 5311(暴力)

题意:要求在一个字符串中找出三段,然后能拼成一个固定的单词,问是否可行 BC周年庆第二题,我枚举了那个单词的切断位置,然后到给的字符串里分别找,然后就没有然后了``` 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 7 char s[105]; 8 char t[15]=" anniv

Hdu 5311 Hidden String

一道查找字符串的题,要求在给出的字符串中找出三段字符串a,b,c,其中a,b,c三个字符串有先后关系,且不能有交集,即原字符串中的一个字母不能被用两次. 这三个字符串拼成“anniversary”. 先后A了两次,第一次用<cstring>头文件中的strncpy和strstr函数.我再昨天也写了一篇随笔,简单介绍了这两个函数的使用方法,可移步至此. 为了确保先后关系,比如“versaryanni”,虽然可以找到“versary”和“anni”但顺序不对,所以不能,必须依次寻找,且第二次和第三

hdu 5311 Hidden String(dfs)(好题)

题意:匹配串为"anniversary",对于每个给定串,为是否存在不多于3段连续子串能拼成匹配串:(n<=100) 思路:两个串从首部开始搜,若匹配次数不大于3则成功,否则不成功: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int t,n,m,len,flag; char ch[15]="anniversary";

hdu 5311 Hidden String dp o(n)算法 深搜

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

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include