hdu 5414 CRB and String(字符串模拟)
来源:互联网 发布:淘宝客户分析 编辑:程序博客网 时间:2024/05/20 01:37
CRB and String
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1658 Accepted Submission(s): 539
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
solution:
可以在s串任意添加字符,问能否添加至和t串相同,担忧要求,必须在某字符c后添加字符d且c!=d,对于这个特殊要求我们可以得出一个结论是s和t的首字符必须相同,且t的首字符连续的长度不能大于s的首字符连续的长度,然后对于字符s我们可以从后往前扫看是否每个字符都是按照这种顺序在t中出现,具体看代码。
tips:这道题要注意两个用例
apl
apple
这个 是Yes,可以每次都在a后加p
aaa
abaa
这也是Yes,即s的首字符连续的长度可以大于t的首字符连续的长度
#include<cstdio>#include<cstring>using namespace std;const int maxn = 1e5 + 200;int num1[30], num2[30];char s1[maxn], s2[maxn];int main(){ int t; scanf("%d", &t); while (t--) { scanf("%s%s", s1, s2); int len1 = strlen(s1), len2 = strlen(s2); int x1 = 0, x2 = 0; while (x1<len1&&s1[x1] == s1[0]) x1++; while (x2<len2&&s2[x2] == s2[0]) x2++; if (x1<x2 || s1[0] != s2[0]) { printf("No\n"); continue; } x2 = len2 - 1; for (int i = len1 - 1; i >= 0; i--) { while (x2 >= 0 && s1[i] != s2[x2]) x2--; } if (x2 >= 0)printf("Yes\n"); else printf("No\n"); } return 0;}
1 1
- hdu 5414 CRB and String(字符串模拟)
- hdu 5414 CRB and String(字符串模拟)
- 贪心,模拟,构造(HDU 5414,CRB and String)
- HDU5414 CRB and String 字符串+模拟+思维
- 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 5414(2015多校10)-CRB and String(字符串处理)
- HDOJ 5414 CRB and String 模拟
- hdu 5414 CRB and String (贪心)
- hdu 5414 CRB and String(贪心)
- HDU 5414 CRB and String(贪心)
- hdu 5414 CRB and String(贪心)
- [思路题] hdu 5414 CRB and String
- HDU 5414 CRB and String(水~)
- 模拟 hdu5414 CRB and String
- Part 2 How to Monitor Java Garbage Collection
- Intent实现简易文件浏览查看器
- fork()函数
- http load介绍
- 自定义View android 像支付宝支付界面的progress
- hdu 5414 CRB and String(字符串模拟)
- secureCRT报错 The remote system refused the connection
- 2013NOIP D1 T2 火柴排队
- Android WebView顶部进度条
- 关于前后端联调(表单提交及处理)的一个小问题
- 富贵险中求?回顾AMD历次决策之是非对错(AMD授权中国生产x86之后)
- UVa 12118 Inspector's Dilemma
- SICP ex1-17 ex-18 ex1-19
- JS中的this