生活随笔
收集整理的這篇文章主要介紹了
codeforces1435 D. Shurikens
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
D. Shurikens
自己感覺差不多寫了個模擬過了59組數據。
明顯這題可能和棧扯上關系,因為很想括號匹配求卡特蘭數的形式
看了大佬博客后發現真的和棧有關于是學習了一波。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std
;
typedef long long ll
;
typedef pair
<int,int> pii
;
const int N
=200010;
int ans
[N
];
stack
<int> q
;
int idx
,n
;
int main()
{IO
;int T
=1;while(T
--){cin
>>n
;bool ok
=1;for(int i
=1;i
<=2*n
;i
++){char op
;cin
>>op
;if(op
=='+') q
.push(++idx
);else{int x
;cin
>>x
;if(q
.empty())ok
=0;else{int id
=q
.top();q
.pop();ans
[id
]=x
;if(ans
[id
]<ans
[id
+1]) ok
=0;}}}if(!ok
) cout
<<"NO\n";else{cout
<<"YES\n";for(int i
=1;i
<=n
;i
++) cout
<<ans
[i
]<<' ';cout
<<'\n';}}return 0;
}
總結
以上是生活随笔為你收集整理的codeforces1435 D. Shurikens的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。