HDU 5414 CRB and String(字符串处理)——多校练习10
来源:互联网 发布:企业生产软件 编辑:程序博客网 时间:2024/05/08 18:57
CRB and String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description
CRB has two strings s and t .
In each step, CRB can select arbitrary characterc of s and insert any character d (d≠c ) just after it.
CRB wants to converts to t . But is it possible?
In each step, CRB can select arbitrary character
CRB wants to convert
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.
1 ≤
1 ≤
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
4abcatcatsdodoappleaapple
Sample Output
NoYesYesNo
Author
KUT(DPRK)
Source
2015 Multi-University Training Contest 10
题意:给你两个字符串s和t,你可以在字符串s中任意选一个字符c,在该字符c后插入一个字符d(d!=c),问经过多次此操作,能否将字符串s转化成字符串t
放上出题人的解题报告解题思路:首先拿到这样的题目,我们当然是来找找怎么样的s是能够转化成t的,经过举例,我们可以得到如下两个条件
①字符串s是字符串t的子串,即t是包含s的字符串,比如说s=cat t=cbadt
②若字符串t前k个字符都相同,那么字符串s的前k个字符也必须相同,比如说 s=aabcd t=aabcde 是可以转化的,而s=aabcd t=aaabcd 则是不可以转化的,因为我们没有办法在a后面插入a,因为题目要求插入的字符d!=选择的字符c
只要符合上述两个条件的字符串s,都可以转化成字符串t
这个时候有些人会疑问,难道后面有不等长的字符串就可以转化了?比如说 s=apple t=appple
虽说我们没办法在p字符后面插入p,但是我们可以在a字符后面插入p,这样我们就可以做到s转化成t了
放上几组样例以供参考
Input
b
ab
Output
No
Input
apple
appapple
Output
Yes
Input
apple
appple
Output
Yes
Input
aa
aaa
Output
No
说了这么多,剩下的靠你们理解咯,老样子,不理解的欢迎提出来
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<math.h>#include<vector>#include<map>#include<set>#include<stdlib.h>#include<cmath>#include<string>#include<algorithm>#include<iostream>#define exp 1e-10using namespace std;const int N = 100005;const int inf = 1000000000;const int mod = 1000000007;char s[N],t[N];int main(){ int T,i,j,k; scanf("%d",&T); while(T--) { scanf("%s%s",s,t); for(k=i=j=0;t[i]!='\0';i++) { if(!k&&t[i]==t[0]&&s[i]!=t[0])//t的前k个字符相等,那么s的前k个字符也必须相等 break; if(t[i]!=t[0]) k=1; if(s[j]!='\0'&&t[i]==s[j])//s是t的子串 j++; } if(t[i]=='\0'&&s[j]=='\0') puts("Yes"); else puts("No"); } return 0;}菜鸟成长记
0 0
- HDU 5414 CRB and String(字符串处理)——多校练习10
- HDU 5414(2015多校10)-CRB and String(字符串处理)
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- HDU 5410 CRB and His Birthday(完全背包)——多校练习10
- HDU 5416 CRB and Tree(dfs+邻接表)——多校练习10
- HDU 5414 CRB and String
- hdu 5414 CRB and String
- HDU 5414 CRB and string
- hdu 5414 CRB and String
- HDU 5414CRB and String
- HDU 5407 CRB and Candies(数学 素数表+预处理+快速幂+乘法逆元)——多校练习10
- HDU 5414 CRB and String (2015 Multi-University Training Contest 10 2015多校联合)
- hdu 5414 CRB and String 2015多校联合训练赛#10 贪心
- hdu 5414 CRB and String (贪心)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String(贪心)
- hdu 5414 CRB and String(贪心)
- 杭电1557
- C++RTTI强制转型
- 我叫MT2 v1.9.5.0 安卓版
- 欢迎使用CSDN-markdown编辑器
- JS门面模式
- HDU 5414 CRB and String(字符串处理)——多校练习10
- HDU 5338(ZZX and Permutations-用线段树贪心)
- eclipse下NDK断点失效(断不住)问题的解决方法
- java比较陌生的关键词
- Advanced Fruits
- 谈谈UI架构设计的演化
- ObjC第六节:(2)OC常用类
- cocos2d js 使用 bmpfont生成的字体文件
- MVC,MVP 和 MVVM 的图示