1 条题解

  • 0
    @ 2024-11-24 15:39:43
    #include<bits/stdc++.h>
    using namespace std;
    int main() {
    	int n;
    	cin>>n;
    	for(int i=0; i<n; i++) {
    		stack<int>s;
    		int x;
    		cin>>x;
    		int a[x+1];
    		int b[x+1];
    		for(int i=0; i<x; i++) {
    			cin>>a[i];//入栈序列
    		}
    		for(int i=0; i<x; i++) {
    			cin>>b[i];//出栈序列
    		}
    		int j=0;
    		for(int i=0;i<x;i++) {
    			s.push(a[i]);		
    				while(!s.empty()&&s.top()==b[j]){
    					s.pop();
    					j++;
    				}		
    		}
    		if(s.empty()){
    			cout<<"Yes"<<endl;
    		}
    		else{
    			cout<<"No"<<endl;
    		}
    
    	}
    }
    

    信息

    ID
    272
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    23
    已通过
    5
    上传者