Codeforces 982 B. Bus of Characters(模拟一个栈)
生活随笔
收集整理的這篇文章主要介紹了
Codeforces 982 B. Bus of Characters(模拟一个栈)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
解題思路:
排序之后模擬一個棧(也可以用真的棧),時間復雜度o(n)。
代碼:
#include <bits/stdc++.h> using namespace std; typedef long long ll;struct node{int val;int idx; }w[200010]; bool cmp(node x, node y){return x.val < y.val; }char a[400010]; stack <node> s; int main(){int n;scanf("%d", &n);for(int i = 1;i <= n; i++) scanf("%d", &w[i].val),w[i].idx = i;sort(w+1, w+1+n, cmp);scanf("%s", a+1);node l;int j = 1;for(int i = 1;i <= 2*n; i++){if(a[i] == '0'){s.push(w[j++]);printf("%d ",w[j-1].idx);}else{l = s.top();printf("%d ",l.idx);s.pop();}}return 0; } 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Codeforces 982 B. Bus of Characters(模拟一个栈)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces 959 E. Ma
- 下一篇: Codeforces 982 C. Cu