HDU 5745 La Vie en rose

暴力。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;

const int maxn=100000+10;
int T,n,m;
char s[maxn],p[maxn];
int ans[maxn];

bool check(int x)
{
    int fs=x,fp=0;
    while(1)
    {
        if(s[fs]==p[fp]) fs++,fp++;
        else
        {
            if(fp==m-1) return 0;
            if(s[fs+1]==p[fp]&&s[fs]==p[fp+1]) fs=fs+2,fp=fp+2;
            else return 0;
        }
        if(fp==m) return 1;
    }
}

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        scanf("%s",s); scanf("%s",p);
        memset(ans,0,sizeof ans);
        for(int i=0;i+m-1<n;i++)
        {
            if(check(i)) ans[i]=1;
            else ans[i]=0;
        }
        for(int i=0;i<n;i++) printf("%d",ans[i]);
        printf("
");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zufezzt/p/5697009.html