HDOJ 5414 CRB and String 模拟
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
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?
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.
4
a
b
cat
cats
do
do
apple
aapple
No
Yes
Yes
No
/* ***********************************************
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 模拟的更多相关文章
- 构造 HDOJ 5414 CRB and String
题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...
- HDU 5414 CRB and String (字符串,模拟)
题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...
- HDU 5414 CRB and String (2015年多校比赛第10场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...
- 【HDOJ 1009】 CRB and String
[HDOJ 1009] CRB and String 每组两个串s t 仅仅由小写字母组成 问从s能不能变成t 改变的操作为选一个字符 在后面加上一个与所选字符不同的字符 这样的操作能够做无数次 问能 ...
- HDU-5414 CRB and String
http://acm.hdu.edu.cn/showproblem.php?pid=5414 题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不 ...
- CRB and String
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- HDU_5414 CRB and String 【字符串】
一.题目 CRB and String 二.分析 对于这题,读懂题意非常重要. 题目的意思是在$s$的基础上,按题目中所描述的步骤,即在$s$中任意选择一个字符$c$,在这个字符后面添加一个不等于$c ...
- B. Obtaining the String(模拟)
比较水的模拟 思路:就是模拟题意 注意:把数组开大点,开始wa了几次就是这个原因 #include<iostream> #include<string> #include< ...
- HDOJ 5416 CRB and Tree DFS
CRB and Tree Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tot ...
随机推荐
- 继承—people
public class People { private double height;//身高 private double weight;//体重 public double getHeight( ...
- IHttpHandler的学习(1)
IHttpHandler的那些事 今晚看了一晚上的IHttpHAndler的知识, 在自定义了Httphandler后,在配置webconfig里配置也是个技术活,什么集成模式,什么asp管道什么的: ...
- POJ 2251 Dungeon Master【BFS】
题意:给出一个三维坐标的牢,给出起点st,给出终点en,问能够在多少秒内逃出. 学习的第一题三维的广搜@_@ 过程和二维的一样,只是搜索方向可以有6个方向(x,y,z的正半轴,负半轴) 另外这一题的输 ...
- Spring AOP 实现数据库读写分离
背景 我们一般应用对数据库而言都是"读多写少",也就说对数据库读取数据的压力比较大,有一个思路就是说采用数据库集群的方案, 其中一个是主库,负责写入数据,我们称之为:写库: 其它都 ...
- numa 和 mysql
cpu numa结构反应的内存访问速度问题: 在多核cpu的时代引入了cpu的numa(非一致内存访问结构): NUMA引入了node的概念,每个物理CPU都被视作一个node,而每个node都有一个 ...
- Linux下通过rdesktop连接Windows远程桌面
rdesktop是linux下支持Windows远程桌面连接的客户端程序,在linux系统下可通过它远程访问Windows桌面,支持多种版本.rdesktop是sourceforge下支持GPL协议的 ...
- CSS命令
border-bottom-right-radius: 10px;/* 文本框的角的弯曲度*/ border-bottom-left-radius: 10px; border-top-left-rad ...
- Percona Monitoring and Management (PMM)安装使用
一.docker安装 参考:http://www.cnblogs.com/liuyongsheng/articles/6595353.html 二.Percona Monitoring and Man ...
- iOS开发——打包报错error: linker command failed with exit code 1
真机运行没问题,打包报错: clang: error: linker command failed with exit code 1 (use -v to see invocation) 原因:在Xc ...
- Linux 常用命令:系统状态篇
前言 Linux常用命令中,有些命令可以用于查看系统的状态,通过了解系统当前的状态,能够帮助我们更好地维护系统或定位问题.本文就简单介绍一下这些命令. 1. 查看系统运行时间--uptime 有时候我 ...