码迷,mamicode.com
首页 > 其他好文 > 详细

HDU-5311

时间:2015-07-26 12:38:32      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:

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. 1l1r1<l2r2<l3r3n

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 (1T100), 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
 
/**
    题意:给你一个串,看是否存在“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

HDU-5311

标签:

原文地址:http://www.cnblogs.com/chenyang920/p/4677280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!