0分help!
查看原帖
0分help!
1034688
_Geburah楼主2024/6/15 20:42
#include<iostream>
using namespace std;
int b[100001],c[100001];
struct stack
{
	int a[100001];
	int sum=1;
	int size()
	{
		return sum-1;
	}
	bool empty()
	{
		if(sum==0)return 0;
		else return 1;
	}
	void push(int x)
	{
		a[sum]=x;
		sum++;
	}
	void pop()
	{
		sum--;
	}
	int top()
	{
		return a[sum];
	}
	void clear()
	{
		a[sum]=0;
		while(sum--)
		{
			a[sum]=0;
		}
	}
};
stack a;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int m;
		cin>>m;
		int top=1,under=1;
		for(int j=1;j<=m;j++)
		{
			
			cin>>b[j];
		}
		for(int j=1;j<=m;j++)
		{
			cin>>c[j];
		}
		for(int j=1;j<=m;j++)
		{
			a.push(b[j]);
			if(a.top()==c[under])
			{
				under++;
				a.pop();
			}
			while(a.top()==c[under])
			{
				a.pop();
				under++;
				if(a.sum==1)
				{
					break;
				}
			}
		}
		if(a.sum==1)cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}
2024/6/15 20:42
加载中...