mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Create 1882.cpp
This commit is contained in:
parent
b8d8bff064
commit
38d845470e
54
QUSTOJ/1882.cpp
Normal file
54
QUSTOJ/1882.cpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#include <iostream>
|
||||
#include <stack>
|
||||
using namespace std;
|
||||
int ans[1024];
|
||||
int main()
|
||||
{
|
||||
int n,m;
|
||||
cin>>n>>m;
|
||||
while(n--)
|
||||
{
|
||||
stack<int> s;
|
||||
int nextTrain=1;
|
||||
for(int i=0;i<m;i++)
|
||||
{
|
||||
cin>>ans[i];
|
||||
}
|
||||
int flag=1;
|
||||
for(int i=0;i<m;i++)
|
||||
{
|
||||
int target=ans[i];
|
||||
if(s.empty())
|
||||
{
|
||||
if(nextTrain<m+1)
|
||||
{
|
||||
s.push(nextTrain);
|
||||
++nextTrain;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag) break;
|
||||
while(s.top()!=target)
|
||||
{
|
||||
if(nextTrain<m+1)
|
||||
{
|
||||
s.push(nextTrain);
|
||||
++nextTrain;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!flag) break;
|
||||
s.pop();
|
||||
}
|
||||
cout<<(flag?"Yes":"No")<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user