# UVa 514 - Rails --- # 題目大意 超級經典題 --- # 題解 用stack模擬進出站 --- ```=C++ #include <bits/stdc++.h> #define ll long long #define pb push_back #define pf push_front #define ft first #define sec second #define pr pair<int,int> #define ISCC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; int t ,n ,m ,a[100005] ,A; int main() { ISCC; while(cin >> n && n) { while(cin >> a[1]) { if(!a[1]){cout << '\n'; break;} for(int i=2 ;i<=n ;i++) cin >> a[i]; A = 1; stack<int> stk; for(int i=1 ;i<=n && A<=n ;i++) { stk.push(i); while(!stk.empty() && stk.top()==a[A]) A++ ,stk.pop(); } if(stk.empty()) cout << "Yes\n"; else cout << "No\n"; } } return 0; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up