g1306374356 @ 2021-07-25 23:19:04
#include<bits/stdc++.h>
using namespace std;
stack <int> check;
int n;
bool judge ()
{
int sum=1,n1,a[100010],b[100010];
cin>>n1;
for(int i=1;i<=n1;i++)
cin>>a[i];
for(int i=1;i<=n1;i++)
cin>>b[i];
for(int i=1;i<=n;i++)
{
check.push(a[i]);
while((check.top())==b[sum])
{
check.pop();
sum++;
if(check.empty())break;
}
}
if(check.empty()) return 1;
else if(!check.empty()) return 0;
while(!check.empty())check.pop();
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
if(judge()==1)cout<<"Yes"<<endl;
else if(judge()==0)cout<<"No"<<endl;
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
stack <int> check;
int n;
int main()
{
cin>>n;
while(n--)
{
int sum=1,n1,a[100010],b[100010];
cin>>n1;
for(int i=1;i<=n1;i++)
cin>>a[i];
for(int i=1;i<=n1;i++)
cin>>b[i];
for(int i=1;i<=n;i++)
{
check.push(a[i]);
while((check.top())==b[sum])
{
check.pop(),sum++;
if(check.empty())break;
}
}
if(check.empty()) cout<<"Yes"<<endl;
else if(!check.empty()) cout<<"No"<<endl;
while(!check.empty())check.pop();
}
return 0;
}
by wweiyi @ 2021-07-25 23:29:20
建议再好好理解一下原理
by g1306374356 @ 2021-07-25 23:47:10
@wweiyi 有哪儿不对吗?
by zhouyujie @ 2021-08-23 21:04:07
把18行(也就是第三个for循环)i<=n改为i<=n1 就可AC