CRB and String

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

Total Submission(s): 491    Accepted Submission(s): 186

Problem Description
CRB has two strings s and t.

In each step, CRB can select arbitrary character c of s and
insert any character d (d ≠ c)
just after it.

CRB wants to convert s to t.
But is it possible?

 
Input
There are multiple test cases. The first line of input contains an integer T,
indicating the number of test cases. For each test case there are two strings s and t,
one per line.

1 ≤ T ≤ 105

1 ≤ |s| ≤ |t| ≤ 105

All strings consist only of lowercase English letters.

The size of each input file will be less than 5MB.
 
Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
 
Sample Input
4
a
b
cat
cats
do
do
apple
aapple
 
Sample Output
No
Yes
Yes
No
 
Author
KUT(DPRK)
 
Source
 

/* ***********************************************
Author :CKboss
Created Time :2015年08月21日 星期五 09时23分23秒
File Name :HDOJ5414.cpp
************************************************ */ #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map> using namespace std; const int maxn=100100; int n,m;
int pip[maxn];
char S[maxn],T[maxn]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T_T;
scanf("%d",&T_T);
while(T_T--)
{
scanf("%s",S);
scanf("%s",T);
n=strlen(S); m=strlen(T);
if(n>m) { puts("No"); }
else if(n==m)
{
if(strcmp(S,T)==0) puts("Yes");
else puts("No");
}
else
{
T[m]='&';
bool flag=true;
if(S[0]!=T[0]) flag=false;
for(int i=0;i<n&&flag;i++)
{
bool temp=false;
int st=0;
if(i) st=pip[i-1]+1;
for(int j=st;j<m;j++)
{
if(S[i]==T[j]&&S[i]!=T[j+1])
{
/// find a point
pip[i]=j;
/// go back
int ni=i+1;
int ed=0;
if(i) ed=pip[i-1]+1;
for(int k=pip[i]-1;k>=ed;k--)
{
if(T[k]==S[ni])
{
pip[ni]=pip[i];
ni++;
}
else break;
}
i=ni-1;
temp=true; break;
}
}
if(temp==false) flag=false;
} /// spc judge start point
if(pip[0]!=0&&flag)
{
int len=1;
for(int i=1;i<n;i++)
{
if(S[i]==S[0]&&pip[0]==pip[i]&&len<pip[0]+1) len++;
else break;
}
if(len!=pip[0]+1) flag=false;
} if(flag==true) puts("Yes");
else puts("No");
}
}
return 0;
}

HDOJ 5414 CRB and String 模拟的更多相关文章

  1. 构造 HDOJ 5414 CRB and String

    题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...

  2. HDU 5414 CRB and String (字符串,模拟)

    题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...

  3. HDU 5414 CRB and String (2015年多校比赛第10场)

    1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...

  4. 【HDOJ 1009】 CRB and String

    [HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...

  5. HDU-5414 CRB and String

    http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不 ...

  6. CRB and String

    CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...

  7. HDU_5414 CRB and String 【字符串】

    一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...

  8. B. Obtaining the String(模拟)

    比较水的模拟 思路:就是模拟题意 注意:把数组开大点,开始wa了几次就是这个原因 #include<iostream> #include<string> #include< ...

  9. HDOJ 5416 CRB and Tree DFS

    CRB and Tree Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

随机推荐

  1. C# 蚁群优化算法实现

    C# 蚁群优化算法实现 需求为(自己编的,非实际项目): 某配送中心进行揽货,目标客户数为50个客户,配送中心目前的运力资源如下: 现有车辆5台 单台运力最大行驶距离200千米 单台运力最大载重公斤1 ...

  2. Pycharm在创建py文件时,如何自动添加默认文件头注释?

    PyCharm是一款很好用的编写Python工程的IDE,用PyCharm创建一个Python文件或者向工程添加一个.py文件时,为了更好的使所编写的代码在各操作环境更好的运行,我们往往需要在.py文 ...

  3. miniUI-SelectGrid 弹出选择表格-翻页选中

    介绍 mini中已经给出 弹出表格的里例子 :MiniUi版本 但是在应用过程中遇到写小问题就是没有办法翻页后一并连之前翻页选中的一起提交 以下是解决方案 正文 下面首先介绍  JS 代码 //存储已 ...

  4. 高德地图和canvas画图结合应用(二)

    上节讲述了如在在高德地图中添加canvas图层,这节就讲述下如何在canvas图层添加鼠标的事件. 在上节脚本的最后加入以下代码: var text; $('#container').on('clic ...

  5. Linux下通过rdesktop连接Windows远程桌面

    rdesktop是linux下支持Windows远程桌面连接的客户端程序,在linux系统下可通过它远程访问Windows桌面,支持多种版本.rdesktop是sourceforge下支持GPL协议的 ...

  6. tf.cast(ndarray,dtype)

    转化为指定的类型,一般是将bool类型转化为其他的数据类型,例如:tf.float32

  7. dijkstra STL 堆优化

    Code: #include<iostream> #include<algorithm> #include<vector> #include<queue> ...

  8. require(): open_basedir restriction in effect. File

    新安装的 lnmp 环境,将项目放上报 require(): open_basedir restriction in effect. File 的错误! 错误日志显示,访问脚本不在 open_base ...

  9. 关于vue自定义事件中,传递参数的一点理解

    例如有如下场景 先熟悉一下Vue事件处理 <!-- 父组件 --> <template> <div> <!--我们想在这个dealName的方法中传递额外参数 ...

  10. caioj 1076 动态规划入门(中链式3:最大的算式)

    一开始写了一个复杂度很大的方法,然后还过了(千万记得开longlong ) #include<cstdio> #include<cstring> #include<alg ...