ZJ c123: 00514 - Rails

這題就開一個Stack依序把車廂push進去(1,2,3,........)
然後看輸入的值是否和當前stack的top一樣
一樣就pop
最後看stack是不是空的
以下為code
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define AC ios::sync_with_stdio(0),cin.tie(0);

int main()
{
AC
ll n;
while(cin>>n&&n)
{
ll f;
while(cin>>f&&f)
{
queue<ll,list<ll>> q;
q.push(f);
stack<ll,list<ll>> s;
for(ll i=1;i<n;i++)
cin>>f,q.push(f);
for(ll i=1;i<=n;i++)
{
s.push(i);
while(s.size()&&s.top()==q.front())
s.pop(),q.pop();
}
cout<<(s.size()?"No\n":"Yes\n");
}
cout<<'\n';
}
}

留言

這個網誌中的熱門文章

TIOJ 1080 . A.逆序數對 (BIT解法)

ZJ d718: Waiting In Line

AtCoder Educational DP Contest E - Knapsack 2