• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# NOIP 模拟 7 考试总结

4小时前 1次浏览

### T1

Code
``````#include<bits/stdc++.h>
#define ri register int
#define p(i) ++i
using namespace std;
namespace IO{
char buf[1<<21],*p1=buf,*p2=buf;
ri x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
}
namespace nanfeng{
#define cmax(x,y) ((x)>(y)?(x):(y))
#define cmin(x,y) ((x)>(y)?(y):(x))
#define FI FILE *IN
#define FO FILE *OUT
typedef unsigned long long ull;
static const int N=1e5+7;
static const ull P=131;
char a[N<<1],b[N];
int st[N],cnt,T,la,lb,ans;
ull ah[N],bh[N],p[N];
inline int check(int x) {
if (ah[x]==bh[lb]-bh[lb-x]*p[x]) return 1;
return 0;
}
inline void init() {cnt=0;ans=0;}
inline int main() {
// FI=freopen("nanfeng.in","r",stdin);
// FO=freopen("nanfeng.out","w",stdout);
p[0]=1;
for (ri i(1);i<=N-5;p(i)) p[i]=p[i-1]*P;
for (ri z(1);z<=T;p(z)) {
init();
scanf("%s",a+1);
scanf("%s",b+lb+1);
for (ri i(1);i<=lb;p(i)) {
if (i<=la&&a[i]==b[lb+1]) st[p(cnt)]=i;
b[i]=a[i];
bh[i]=ah[i]=ah[i-1]*P+(ull)(a[i]);
}
lb+=1;
if (lb<=la&&a[lb]==b[lb]) {printf("%dn",ans=lb);continue;}
bh[lb]=bh[lb-1]*P+(ull)(b[lb]);
for (ri i(cnt);i;--i) if (check(st[i])) {ans=st[i];break;}
printf("%dn",ans);
}
return 0;
}
}
int main() {return nanfeng::main();}
``````