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. Codeforces 667C Reberland Linguistics 记忆化搜索

    链接 Codeforces 667C Reberland Linguistics 题意 给你一个字符串,除去前5个字符串后,使剩下的串有长度为2或3的词根组成,相邻的词根不能重复.找到所有的词根 思路 ...

  2. json数据字典,以及数据在下拉框中显示

    建立person_vocation.json数据字典文件,内容: [ {"id":1,"disabled":false,"selected" ...

  3. UVa 208 Firetruck【回溯】

    题意:给出一个n个节点的无向图,以及某个节点k,按照字典序从小到大输出从节点1到节点k的所有路径 看的题解 http://blog.csdn.net/hcbbt/article/details/975 ...

  4. js对浏览器产生的影响

     Js 是单线程执行引擎.在我们动态修改一些属性时会产生两种效果:    1.Repaint ----- 一部分重画,修改 div 的颜色呀,但是尺寸没有改变.    2.Reflow ---- 元素 ...

  5. python的模块导入机制

    在python中用import或者from...import来导入相应的模块. 模块(Module)其实就是一些函数和类的集合文件,它能实现一些相应的功能,当我们需要使用这些功能的时候,直接把相应的模 ...

  6. bzoj1025 [SCOI2009]游戏 动态规划

    题目描述 对于一些长度为n的排列,将其作为一个置换,那么可能有一个自置换的次数使其回到1,2,3,...,n的情况.求对于所有能够回到1,2,3..,n的排列,不同的次数共有多少种. 题解来自黄学长 ...

  7. P2633 Count on a tree(主席树)

    题目描述 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点间第K小的点权.其中lastans是上一个询问的答案,初始为0,即第一个 ...

  8. 题解 P2431 【正妹吃月饼】

    假如做这道题想着用如下朴实的模拟,那肯定要WA至少4个点. #include <iostream> #include <cstdio> using namespace std; ...

  9. LocalDateTime在spring boot中的格式化配置

    在项目中日期格式化是最常见的问题,之前涉及的 java.util.Date 和 java.util.Calendar 类易用性差,不支持时区,非线程安全,对日期的计算方式繁琐,而且容易出错,因为月份是 ...

  10. ImageLoader的简单分析(二)

    在<ImageLoader的简单分析>这篇博客中对IImageLoader三大组件的创建过程以及三者之间的关系做了说明.同一时候文章的最后也简单的说明了一下ImageLoader是怎么通过 ...