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 ...
随机推荐
- Spring深入浅出(一)IOC的基本知识
Spring前言 Spring是一个企业级开发框架,为解决企业级项目开发过于复杂而创建的,框架的主要优势之一就是分层架构,允许开发者自主选择组件. Spring的两大核心机制是IOC(控制反转)和AO ...
- strlen() 和 sizeof() 的区别
1.strlen() 时函数,他在程序运行时才能计算.它的参数类型要求时 char *,且必须是以'/0'结尾.数组在传入时已经退化为指针.它的作用是返回数组中字符串的长度. 2.sizeof()时运 ...
- Blink Coordinate Spaces
Blink Coordinate Spaces Blink Coordinate Spaces Types of Zoom There are two types of zoom in Chromiu ...
- yii2.0缓存篇之页面缓存
页面缓存: 如果整个页面都不会发生改变,就可以使用页面缓存缓存整个页面. public function behaviors(){ //此方法[也叫行为]会提前控制器内其他方法执 ...
- 学习Go语言之使用channel避免竞态问题
// 使用channel避免竞态问题 package main import ( "fmt" "sync" ) var ( i int wg sync.Wait ...
- 紫书 例题 10-17 UVa 1639(数学期望+分数处理+处理溢出)
设当前有k个,那么也就是说拿到其他图案的可能是(n-k)/n 那么要拿到一个就要拿n/(n-k)次 所以答案就是n(1/n + 1/(n-1) ......1/2 + 1 / 1) 看起来很简单,但是 ...
- CSU 1506 Double Shortest Paths
1506: Double Shortest Paths Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 49 Solved: 5 Description ...
- Python 调用snmp自定义OID实现监控
http://kkkkkk.blog.51cto.com/468162/1172726 http://blog.csdn.net/mirahs/article/details/49619729
- WEB前端,混合排版,有的宽有的窄,滚动会出现空白处,怎么办。
多数时候出现空白都是由于有滚动栏滚到一边就会产生空白. overflow-x: hidden; 在最大图的那个div里写这句.
- SQL Source Control
https://documentation.red-gate.com/display/SOC5/SQL+Source+Control+5+documentation Working with migr ...