不食嗟来之食 @ 2022-07-14 17:00:43
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int e=1e5+5;
int n,q,a[e],b[e],v[e];
int todi(int cnta,int cntb)
{
while(cnta<=n)
{
v[cnta-cntb+1]=a[cnta];
if(v[cnta-cntb+1]==b[cntb])
{
cntb++;
}
cnta++;
}
while(cntb<=n)
{
if(v[n-cntb+1]==b[cntb])
{
cntb++;
continue;
}
else return 0;
}
return 1;
}
int main()
{
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
memset(v,0,sizeof(v));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%d",&n);
for(int j=1;j<=n;j++)scanf("%d",&a[j]);
for(int j=1;j<=n;j++)scanf("%d",&b[j]);
if(todi(1,1)) printf("Yes\n");
else printf("No\n");
}
return 0;
}
蒟蒻求帮orz,感谢大佬们
by 皓月星辉 @ 2022-07-15 21:06:02
不一定要全部进栈才一个个出栈
by 皓月星辉 @ 2022-07-15 21:06:38
进站后马上出站