BestCoder Round #48 ($)HDU5284 wyh2000 and a string problem

53 篇文章 0 订阅
49 篇文章 0 订阅


wyh2000 and a string problem

                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)
                                                                   Total Submission(s): 789    Accepted Submission(s): 378


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  v s, 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


出题人:本题是一道送分的字符串题。这里给出两种解法。


1:维护一个类似栈的结构,存储wyh2000实际看到的字符串。扫描整个字符串,每看到两个相邻的

v就往栈中加入一个\text{w}w;否则看到什么就加入什么。最后扫一遍看\text{wyh}wyh是不是栈中元素组成的串的子序列即可。


2:我们寻找一个ii,使得s_i=\text{v}si=vs_{i+1}=\text{v}si+1=v并且ii尽量小。然后我们寻找一个jj,使得s_j=\text{w}sj=wjj尽量小。

我们再寻找一个kk,使得sk=y,min(i+1,j)<kkk尽量小。然后我们寻找一个ll,使得s_l=\text{h},k<lsl=h,k<l

如果我们能找到符合条件的i,k,li,k,l或符合条件的
j,k,l
j,k,l
,那么答案就是\text{Yes}Yes,否则答案就是\text{No}No


#include
   
   
    
    
#include
    
    
     
     
#include
     
     
      
      
using namespace std;
char a[3146728];
int main()
{
    int t,l,i,j,flag;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%s",a);
        flag=0;
        l=strlen(a);
        for(i=0;i
      
      
     
     
    
    
   
   






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值