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. django 笔记17 ModelForm

    Model 数据库操作 验证 验证 Form -class LoginForm(Form): email = fields.EmailField() is_valid 每一个字段进行正则(字段内置正则 ...

  2. DC、CDC及CDC的各个子类

      设备描述表是一个包含设备信息的结构体(物理设备如显示器.打印机),MFC中关于图像操作都需要DC来完成.HDC是Windows的一种数据类型,是设备描述句柄:CDC是MFC封装的Windows 设 ...

  3. 继承—people

    public class People { private double height;//身高 private double weight;//体重 public double getHeight( ...

  4. Activity的启动模式和onNewIntent()

    1:首先,在默认情况下,当您通过Intent启到一个Activity的时候,就算已经存在一个相同的正在运行的Activity,系统都会创建一个新的Activity实例并显示出来.为了不让Activit ...

  5. [BJWC2012]冻结 分层图最短路

    昨晚飞行路线之后,这道题就应该能一眼切了 题目当然也不难,跑一遍分层图最短路即可 Code: #include<cstring> #include<algorithm> #in ...

  6. HDU-1878 欧拉回路 欧拉回路

    题目链接:https://cn.vjudge.net/problem/HDU-1878 题意 中文题,而且就是单纯的欧拉回路 思路 判断连通图 用并查集会很好,bfs亦可 一时脑抽用bfs过了这个题, ...

  7. Centos7:yum安装apache,编译安装php5.6,不解析php的解决方法

    首先,说一下问题发生的场景: 因为懒,所以用 yum 安装 apache ,因为 centos 的源自带 php 5.4 不能符合环境要求,而不想用其他源,所以选择源码编译安装 php 5.6 安装完 ...

  8. JAVA JS 中的 modulus exponent 生成 C# 公匙

    C#用的是xml,里面是base64编码的.你上面的就是hex格式,只要把上面hex格式转成byte数组,然后在base64编码就可以了. public static byte[] Hex2Byte( ...

  9. java RSA加密算法

    [转]RSA加密算法   RSA公钥加密算法是1977年由Ron Rivest.Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的.RSA取名来自开发他们三者的名字.RSA是目前 ...

  10. C++里面关于虚函数的一些注意点

    最后,总结一下关于虚函数的一些常见问题: 1) 虚函数是动态绑定的,也就是说,使用虚函数的指针和引用能够正确找到实际类的对应函数,而不是执行定义类的函数.这是虚函数的基本功能,就不再解释了. 2) 构 ...