HDU-5414 CRB and String
http://acm.hdu.edu.cn/showproblem.php?pid=5414
题意:给定字符串s和t,可以在s里面选一个字符c,然后任选一个字符d(d!=c)将d插入到c的后面,问能不能将s变为t。
分析:只要前面t串连续的字符==s字符串,而且保证s是t的子串。本来想不通s:aabaa,t:aabaaaa,后面四个a怎么插,后来才想明白,后面的a都可以插在b后面,就可以了。
CRB and String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 676 Accepted Submission(s):
256
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?
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.
to t, otherwise output "No".
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; char s[],t[];
int main()
{
int r;
scanf("%d",&r);
getchar();
while(r--)
{
int i,j;
scanf("%s",s);
scanf("%s",t);
int len1=strlen(s);
int len2=strlen(t);
int flag=;
for(i=;i<len2;i++)
if(t[i]!=t[])
break;//找到t串的第一个不连续的位置
for(j=;j<i;j++)//看s的前i个子串是否连续
if(s[j]!=t[j])
{
flag=;
break;
}
j=i;
for(;j<len1;j++)
{
for(;i<len2;i++)
{//找到下一个和s相等的地方
if(t[i]==s[j])
break;
}
if(i==len2)
{
flag=;
break ;//如果t找完了还没跳出证明s不是t的子串
}
i++;
}
if(s[]!=t[])
flag=;
if(flag)
printf("Yes\n");
else
printf("No\n");
}
return ;
}
HDU-5414 CRB and String的更多相关文章
- HDU 5414 CRB and String (2015年多校比赛第10场)
1.题目描写叙述:点击打开链接 2.解题思路:本题要求推断字符串s是否能通过加入若干个字符得到字符串t. 首先,能够知道,s必须是t的一个子串(注意:不是连续子串). 第二.因为插入的新字符和它前面的 ...
- HDU 5414 CRB and String (字符串,模拟)
题意:给两个字符串s和t,如果能插入一些字符使得s=t,则输出yes,否则输出no.插入规则:在s中选定一个字符c,可以在其后面插入一个字符k,只要k!=c即可. 思路:特殊的情况就是s和t的最长相同 ...
- HDOJ 5414 CRB and String 模拟
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- 构造 HDOJ 5414 CRB and String
题目传送门 题意:给两个字符串s,t,可以在s字符串任意位置后面插入字符c(与前面的不同),问是否能够将s转换为t字符串 构造:首先lens > lent 或者 s[1] != t[1] 一定是 ...
- HDU 5842 Lweb and String(Lweb与字符串)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- CRB and String
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- hdu 4850 Wow! Such String! 欧拉回路
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4080264.html 题目链接:hdu 4850 Wow! Such String! 欧拉回 ...
- hdu 3553 Just a String (后缀数组)
hdu 3553 Just a String (后缀数组) 题意:很简单,问一个字符串的第k大的子串是谁. 解题思路:后缀数组.先预处理一遍,把能算的都算出来.将后缀按sa排序,假如我们知道答案在那个 ...
- Hdu 5416 CRB and Tree (bfs)
题目链接: Hdu 5416 CRB and Tree 题目描述: 给一棵树有n个节点,树上的每条边都有一个权值.f(u,v)代表从u到v路径上所有边权的异或值,问满足f(u,v)==m的(u, v) ...
随机推荐
- jQuery 1.4.4 中 function( window, undefined ) 写法原因
读 jQuery 1.4.4 版本代码的时候,发现下面的写法: (function( window, undefined ) { ... // code goes here })(window); w ...
- Linux 源码的安装 3个步骤
http://www.oseye.net/question/96 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install). Configure是一 ...
- Windows phone 8 安装在 VMWare上错误的各种解决方案
http://windowsasusual.blogspot.jp/2013/01/how-to-launch-windows-phone-8-emulator.html Hardware requi ...
- tar解压去除文件夹
tar zxvf test.tar.gz --strip-components 1 解压到当前目录,并去除一级目录
- php练习1——计算器
目标:输入两个数,计算两个数的和/差/积/商 程序如下:两个文件jiSuanQi.html和jiSuanQi.php 结果如下:
- rsync与inotify 数据同步
发布:thebaby 来源:脚本学堂 [大 中 小] 本文介绍下,在linux系统中,使用rsync与inotify实现数据同步的一个实例,有研究文件同步的朋友可以作个参考.本文转自:ht ...
- supervisor---------------------------------常用
第一个 supervisor 的启动 supervisord -c ~/supervisord.conf 这个是如果没有服务没有启动,则使用本脚本启动 进程的设置 [program:blog] ...
- NodeJS+Express+Socket.io的一个简单例子
关键字:NodeJS,Express,Socket.io. OS:Windows 8.1 with update pro. 1.安装NodeJS:http://nodejs.org/. 2.初始化一个 ...
- UIApplication sharedApplication 的常用使用方法-b
下面是这个类的一些功能:1.设置icon上的数字图标 //设置主界面icon上的数字图标,在2.0中引进, 缺省为0 [UIApplicationsharedApplication].applicat ...
- Memcache仅仅支持简单数据类型
Memcache仅仅支持简单数据类型 ,复杂数据类型需要应用自己处理 从数据库当中取出数据[User [id=1, username=guowuxin, password=guowuxin], Use ...