热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

HDU-5284-wyh2000andastringproblem(BestCoderRound#48($))

wyh2000andastringproblemTimeLimit:20001000MS(JavaOthers)MemoryLimit:13107265

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(T105), 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=vsi+1=v并且i尽量小。然后我们寻找一个j,使得sj=wj尽量小。我们再寻找一个k,使得sk=y,min(i+1,j)<kk尽量小。然后我们寻找一个l,使得sl=h,k<l。如果我们能找到符合条件的i,k,l或符合条件的j,k,l,那么答案就是Yes,否则答案就是No


#include
#include
#include
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,使得wy前面,yh前面即可。
有一天小学生拿着一个串问他“wyh是不是这个串的子序列?”
但是wyh2000有重度近视眼,如果字符串中有一段连续的v(至少两个),那么他会把它看成一个w。例如,字符串vvv会被看成w,字符串vvwvvv会被看成www,字符串vwvv会被看成vww。
请问wyh2000会怎么回答这个问题?
输入描述
第一行为数据组数T(1T105)。
接下来T行,每行一个字符串,表示小学生拿来问wyh2000的串。
总串长不超过3145728。只包含小写字母。
hack数据字符串长度不超过100000。
输出描述
对于每组数据,如果wyh2000会把wyh看成该串的子串,那么输出一行Yes,否则输出一行No
输入样例
4
woshiyangli
woyeshiyangli
vvuuyeh
vuvuyeh
输出样例
No
Yes
Yes
No



 


推荐阅读
author-avatar
身强体硕之大家来锻炼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有