xinxuzhi @ 2024-12-01 08:20:37
#include<bits/stdc++.h>
using namespace std;
stack<int>q;
int m,n,a[1005],b[1005],sum=1;
int main()
{
cin>>m;
for(int i=1;i<=m;i++){
cin>>n;
for(int j=1;j<=n;j++){
cin>>a[j];
cin>>b[j];
q.push(a[j]);
while(q.top()==b[sum]){
q.pop();
sum++;
while(sum==n+1){
if(q.empty()){
cout<<"Yes"<<endl;
break;
}
else{
cout<<"No"<<endl;
break;
}
}
}
}
}
return 0;
}
by wsy_I @ 2024-12-10 12:55:14
@xinxuzhi
我也是,呜呜呜
#include<bits/stdc++.h>
#define MAXN (int)(1e5+1e1)
using namespace std;
int q,n,a[MAXN],b[MAXN],ap=0,bp=0;
stack<int> st;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>q;
for(int i=1;i<=q;i++){
cin>>n;
for(int j=1;j<=n;j++) cin>>a[j];
for(int j=1;j<=n;j++) cin>>b[j];
for(int j=1;j<=n;j++){
while(st.top()!=a[++ap]) st.push(b[++bp]);
while(st.top()==a[++ap]) st.pop();
}
if(st.empty()) cout<<"Yes"<<endl;
else{
while(!st.empty()) st.pop();
cout<<"No"<<endl;
}
}
return 0;
}
by wsy_I @ 2024-12-10 13:02:04
找到两个问题,但还是会RE
by wsy_I @ 2024-12-10 13:04:10
#include<bits/stdc++.h>
using namespace std;
stack<int>q;
int m,n,a[/*改动1*/100005],b[100005],sum=1;
int main()
{
cin>>m;
for(int i=1;i<=m;i++){
cin>>n;
for(int j=1;j<=n;j++){
cin>>a[j];
cin>>b[j];
q.push(a[j]);
while(q.top()==b[sum]){
q.pop();
sum++;
while(sum==n+1){
if(q.empty()){
cout<<"Yes"<<endl;
break;
}
else{
cout<<"No"<<endl;
/*改动2*/ while(!q.empty()) q.pop();
break;
}
}
}
}
}
return 0;
}
by wsy_I @ 2024-12-10 13:08:49
看不太懂代码@xinxuzhi