hdu5414 CRB and String(构造,模拟)

题目:

CRB and String

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1114    Accepted Submission(s): 384


Problem Description
CRB has two strings s 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?
 

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.
 

Output
For each test case, output "Yes" if CRB can convert s to t, otherwise output "No".
 

Sample Input
 
   
4 a b cat cats do do apple aapple
 

Sample Output
 
   
No Yes Yes No
 

Author
KUT(DPRK)
 

Source
2015 Multi-University Training Contest 10
 

Recommend
wange2014

题意:给两个字符串s和t,可以在字符串s的任意字符后面添加和前一个字符不相同的字符,问s能不能转化为t。

思路:由于只能添加和前一个字符不同的字符,所以s和t的开始的字符必须相同并且s的起始连续的相同字符个数要大于等于t的,不然只能通过添加和前一个字符相同的字符来使s等于t。还有一个限制条件是s必须是t的子序列,也就是说s中出现的字符必须在t中出现而且s的字符的位置还要小于等于t中相应字符的位置,因为添加字符只能把字符向后移不能向前移。

代码:

#include 
#include 
#include 
#include 
#include 
#include
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

#define PB push_back
#define MP make_pair

#define REP(i,x,n) for(int i=x;i<(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define OI(X) printf("%d",X);
#define RS(X) scanf("%s", (X))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define Swap(a, b) (a ^= b, b ^= a, a ^= b)
#define Dpoint  strcut node{int x,y}
#define cmpd int cmp(const int &a,const int &b){return a>b;}

 /*#ifdef HOME
    freopen("in.txt","r",stdin);
    #endif*/
const int MOD = 1e9+7;
typedef vector VI;
typedef vector VS;
typedef vector VD;
typedef long long LL;
typedef pair PII;
//#define HOME

int Scan()
{
	int res = 0, ch, flag = 0;

	if((ch = getchar()) == '-')				//判断正负
		flag = 1;

	else if(ch >= '0' && ch <= '9')			//得到完整的数
		res = ch - '0';
	while((ch = getchar()) >= '0' && ch <= '9' )
		res = res * 10 + ch - '0';

	return flag ? -res : res;
}
/*----------------PLEASE-----DO-----NOT-----HACK-----ME--------------------*/



char s[100000+5],t[100000+5];
int cnt1[26],cnt2[26];
int main()
{int T;
RI(T);
while(T--)
{
    scanf("%s",s);
    scanf("%s",t);
    if(!strcmp(s,t))
    {
        printf("Yes\n");
        continue;
    }
    if(strlen(s)>=strlen(t)&&strcmp(s,t)!=0)
    {
        printf("No\n");
        continue;
    }
    int len1=strlen(s);
    int len2=strlen(t);
    int ok=1;
    int num1=0,num2=0;
    for(int i=0;inum1)
    {
        printf("No\n");
        continue;
    }
    if(t[0]!=s[0])
    {
        printf("No\n");
        continue;
    }
    MS0(cnt1);
    MS0(cnt2);
   int i;
   int cur=0;
   for(i=0;i


你可能感兴趣的:(ACM,-----模拟,-----构造)