热门标签 | 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



 


推荐阅读
  • 题目描述:给定n个半开区间[a, b),要求使用两个互不重叠的记录器,求最多可以记录多少个区间。解决方案采用贪心算法,通过排序和遍历实现最优解。 ... [详细]
  • 题目Link题目学习link1题目学习link2题目学习link3%%%受益匪浅!-----&# ... [详细]
  • Codeforces Round #566 (Div. 2) A~F个人题解
    Dashboard-CodeforcesRound#566(Div.2)-CodeforcesA.FillingShapes题意:给你一个的表格,你 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • 本文详细探讨了VxWorks操作系统中双向链表和环形缓冲区的实现原理及使用方法,通过具体示例代码加深理解。 ... [详细]
  • 精通C++并非易事,为何它比其他语言更难掌握?这主要归因于C++的设计理念,即不强迫用户接受特定的编程风格或限制创新思维。本文探讨了如何有效学习C++,并介绍了几本权威的学习资源。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • Java 中 Writer flush()方法,示例 ... [详细]
  • 主要用了2个类来实现的,话不多说,直接看运行结果,然后在奉上源代码1.Index.javaimportjava.awt.Color;im ... [详细]
  • C++: 实现基于类的四面体体积计算
    本文介绍如何使用C++编程语言,通过定义类和方法来计算由四个三维坐标点构成的四面体体积。文中详细解释了四面体体积的数学公式,并提供了两种不同的实现方式。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • UNP 第9章:主机名与地址转换
    本章探讨了用于在主机名和数值地址之间进行转换的函数,如gethostbyname和gethostbyaddr。此外,还介绍了getservbyname和getservbyport函数,用于在服务器名和端口号之间进行转换。 ... [详细]
  • 本文探讨了如何在给定整数N的情况下,找到两个不同的整数a和b,使得它们的和最大,并且满足特定的数学条件。 ... [详细]
  • 本文探讨了 C++ 中普通数组和标准库类型 vector 的初始化方法。普通数组具有固定长度,而 vector 是一种可扩展的容器,允许动态调整大小。文章详细介绍了不同初始化方式及其应用场景,并提供了代码示例以加深理解。 ... [详细]
  • 文件描述符、文件句柄与打开文件之间的关联解析
    本文详细探讨了文件描述符、文件句柄和打开文件之间的关系,通过具体示例解释了它们在操作系统中的作用及其相互影响。 ... [详细]
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社区 版权所有