Title Address: HDU 5414
Test instructions: Ask to determine whether the string s can be added several characters to get the string t
Idea: This problem looks complex, in fact, a careful analysis, successful conversion contains only two cases. The first is that because the new character required to be inserted differs from the character C in front of it, if there is x continuous C in T, then there must be x consecutive C in S, and the second is a discontinuous substring of t that must be s.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>#include <bitset>#pragma COMMENT (linker, "/stack:102400000,102400000")using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-7;Const intmaxn=1e5+Ten;CharS[MAXN],T[MAXN];intN,m;intLen1,len2;intCheck () {intI,j; for(i=1; i<len2;i++)if(t[i]!=t[0]) Break;//Find the first discontinuous position of the T-string for(j=0; j<i;j++)//See if the first I substring of S is continuous if(S[j]!=t[j])return 0; for(;j<len1;) { for(; i<len2;i++) {//Find the next and s equal places if(T[i]==s[j]) Break; }if(I==LEN2)return 0;//If T is finished, it's not yet out of the proof that s is not a substring of Ti++; j + +; }return 1;}intMain () {intTscanf("%d", &t); while(t--) {scanf('%s '%s ', s,t); len1=strlen(s); Len2=strlen(t);if(check ())puts("Yes");Else puts("No"); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5414 (2015 + schools)-CRB and string (string processing)