HDU-5284-wyh2000 and a string problem(BestCoder Round #48 ($))

wyh2000 and a string problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)

Total Submission(s): 492    Accepted Submission(s): 239

Problem Description

Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings.

A subsequence of a string s is
a string that can be derived from s by
deleting some characters without changing the order of the remaining characters. You can delete all the characters or none, or only some of the characters.

He also teaches the pupils how to determine if a string is a subsequence of another string. For example, when you are asked to judge whether wyh is
a subsequence of some string or not, you just need to find a character w,
a y,
and an h,
so that the w is
in front of the y,
and the y is
in front of the h.

One day a pupil holding a string asks him, "Is wyh a
subsequence of this string?"

However, wyh2000 has severe myopia. If there are two or more consecutive character vs,
then he would see it as one w.
For example, the string vvv will
be seen as w,
the string vvwvvv will
be seen as www,
and the string vwvv will
be seen as vww.

How would wyh2000 answer this question?

Input

The first line of the input contains an integer T(T≤105),
denoting the number of testcases.

N lines
follow, each line contains a string.

Total string length will not exceed 3145728. Strings contain only lowercase letters.

The length of hack input must be no more than 100000.

Output

For each string, you should output one line containing one word. Output Yes if
wyh2000 would consider wyh as
a subsequence of it, or No otherwise.

Sample Input

4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh

Sample Output

No
Yes
Yes
No

Source

BestCoder Round #48 ($)

Recommend

hujie   |   We have carefully selected several similar problems for you:  5287 5286 5285 5283 5282

官方解析:

1001. wyh and string problem
本题是一道送分的字符串题。这里给出两种解法。

1.维护一个类似栈的结构,存储wyh2000实际看到的字符串。扫描整个字符串,每看到两个相邻的v就往栈中加入一个w;否则看到什么就加入什么。最后扫一遍看wyh是不是栈中元素组成的串的子序列即可。

2.我们寻找一个i,使得si=v且si+1=v并且i尽量小。然后我们寻找一个j,使得sj=w且j尽量小。我们再寻找一个k,使得sk=y,min(i+1,j)<k且k尽量小。然后我们寻找一个l,使得sl=h,k<l。如果我们能找到符合条件的i,k,l或符合条件的j,k,l,那么答案就是Yes,否则答案就是No。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX= 3145728+5;
char a[MAX];
int main()
{
    int t;
    char tar[4]="wyh";
    scanf("%d",&t);
    while(t--)
    {
        int flag=0;
        int i=0,j=0,k=0;
        scanf("%s",a);
        for(i=0;a[i+1];i++)
        {
            if((a[i]=='v'&&a[i+1]=='v'))
            {
                a[i]='w';
            }
            if(a[i]==tar[k])
            {
                k++;
            }
            if(k==3)
            {
                flag=1;
                break;
            }
        }
        for(;a[i];i++)
        {
            if(a[i] == tar[k]) k++;
            if(k == 3)
            {
                flag=1;
                break;
            }
        }
        if(flag)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}

中文题在下面:

wyh2000 and a string problem

Accepts: 428

Submissions: 1313

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

Memory Limit: 131072/65536 K (Java/Others)

问题描述

青年理论计算机科学家wyh2000在教小学生一些基础的字符串概念。
定义一个字符串s的子序列为将s中一些元素删掉得到的字符串。可以删掉全部元素,可以不删,也可以只删一些。
他还教了小学生如何判断一个串是不是另一个串的子序列。比如给你一个串,要求判断wyh是不是它的子序列,那么你只需要找一个w,找一个y,再找一个h,使得w在y前面,y在h前面即可。
有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”
但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w。例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww。
请问wyh2000会怎么回答这个问题?

输入描述

第一行为数据组数T(1≤T≤105)。
接下来T行,每行一个字符串,表示小学生拿来问wyh2000的串。
总串长不超过3145728。只包含小写字母。
hack数据字符串长度不超过100000。

输出描述

对于每组数据,如果wyh2000会把wyh看成该串的子串,那么输出一行Yes,否则输出一行No。

输入样例

4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh

输出样例

No
Yes
Yes
No

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-08 23:45:36

HDU-5284-wyh2000 and a string problem(BestCoder Round #48 ($))的相关文章

HDU 5284 wyh2000 and a string problem(字符串,水)

题意:比如给你一个串,要求判断wyh是不是它的子序列,那么你只需要找一个w,找一个y,再找一个h,使得w在y前面,y在h前面即可.有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”.但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w.例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww.请问wyh2000会怎么回答这个问题?输出yes和no. 思路:其实就是将两个以上的v换成w,再来看是否能有'wyh'子

hdu 5284 wyh2000 and a string problem(没有算法,只考思维,字符数组得开20万,不然太小了)

代码: #include<cstdio> #include<cstring> using namespace std; char s[200000]; int main() { int t; scanf("%d",&t); while(t--) { scanf("%s",s); int w=0,y=0,h=0; int len=strlen(s); for(int i=0; i<len; i++) { if(w==0&&

HDU 5284 wyh2000 and a string problem(错误总结)

---恢复内容开始--- 题目链接:戳我(英文),戳我(中文) 题目大意: 看中文 样例解释: 略 解题思路: for循环跑一遍,遇到 vv 就变成 w 就行了 错误的代码 int k = 0, i; for(i = 0; str[i+1]; i++) { printf("%d %c\n", i, str[i]); if(str[i] == 'v' && str[i+1] == 'v') { i = i + 1; //这里不能加1 str[i] = 'w'; //k++

[Water]Hdu 5284 wyh2000 and a string problem

#include <cstdio> #include <cstring> using namespace std; const int MAXN=10000000+5; char a[MAXN]; int t; char b[3]={'w','y','h'}; int main() { scanf("%d",&t); getchar(); while(t--){ gets(a); for(int i=0;a[i+1];++i)if(a[i]=='v'&a

bestcoder 47# wyh2000 and a string problem (水题)

wyh2000 and a string problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 484    Accepted Submission(s): 232 Problem Description Young theoretical computer scientist wyh2000 is teaching you

HDU5284——水,strlen坑——wyh2000 and a string problem

Young theoretical computer scientist wyh2000 is teaching young pupils some basic concepts about strings. A subsequence of a string s is a string that can be derived from s by deleting some characters without changing the order of the remaining charac

hdu 5066 Harry And Physical Teacher(Bestcoder Round #14)

Harry And Physical Teacher Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 91    Accepted Submission(s): 68 Problem Description As we all know, Harry Porter learns magic at Hogwarts School. How

hdu 5067 Harry And Dig Machine(BestCoder Round #14)

Harry And Dig Machine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 332    Accepted Submission(s): 104 Problem Description As we all know, Harry Porter learns magic at Hogwarts School. Howeve

HDU 5778 abs(暴力枚举)——BestCoder Round #85 1003

传送门 abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1474    Accepted Submission(s): 511 Problem Description Given a number x, ask positive integer y≥2, that satisfy the following condition