标签:bzoj3942 usaco2015 censoring kmp
#include <stdio.h>
int main()
{
puts("转载请注明出处[vmurder]谢谢");
puts("网址:blog.csdn.net/vmurder/article/details/44959895");
}
有一个S串和一个T串,长度均小于
用
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1001000
using namespace std;
char s[N],t[N];
int n,m,pre[N],fix;
int f[N],stk[N],top;
int main()
{
freopen("test.in","r",stdin);
int i;
scanf("%s%s",s+1,t+1);
m=strlen(s+1),n=strlen(t+1);
for(fix=0,i=2;i<=n;i++)
{
while(fix&&t[fix+1]!=t[i])fix=pre[fix];
if(t[fix+1]==t[i])fix++;
pre[i]=fix;
}
for(i=1;i<=m;i++)
{
fix=f[stk[top]];
while(fix&&t[fix+1]!=s[i])fix=pre[fix];
if(t[fix+1]==s[i])fix++;
if(fix==n)top-=(n-1);
else f[i]=fix,stk[++top]=i;
}
for(i=1;i<=top;i++)printf("%c",s[stk[i]]);
return 0;
}
【BZOJ3942】【Usaco2015 Feb】Censoring KMP
标签:bzoj3942 usaco2015 censoring kmp
原文地址:http://blog.csdn.net/vmurder/article/details/44959895