T1263-简单模拟,原列用队列+存放堆用堆栈
<!--Markdown-->
纯模拟
c++代码
------------
#include<bits/stdc++.h>
using namespace std;
int n,m,k,c;
int main(){
cin>>n>>m>>k;
while(k--){
int need=1;
queue<int>q;
stack<int>s;
int x,y=0;
for(int i=1;i<=n;i++){
cin>>x;
q.push(x);
}
while(1){
if(!q.empty()){
x=q.front();
}
if(!s.empty()){
y=s.top();
}
if(x==need){
need++;
q.pop();
c++;
}
else if(y==need){
need++;
s.pop();
c++;
}
else{
if(!q.empty()){
q.pop();
s.push(x);
}
else{
cout<<"NO"<<endl;
break;
}
}
if(s.size()>m){
need=1;
cout<<"NO"<<endl;
break;
}
if(c==n){
need=1;
c=0;
cout<<"YES"<<endl;
break;
}
}
}
return 0;
}
Comments: