首页 > 其他分享 >D - Bank

D - Bank

时间:2023-03-27 21:56:15浏览次数:42  
标签:abc294 int wait include called Bank 取钱者

D - Bank

https://atcoder.jp/contests/abc294/tasks/abc294_d

 

思路

准备一个优先队列wait,用于所有取钱者的排队,按照ID从小到大排队;

准备一个集合called,用于存储所有已经被叫到号的取钱者;

每次teller叫号后,将叫到号的取钱者放入called集合中;

每当取钱者到柜台后,从called集合中删除此取钱者;

对于3 event, 取的called中最小的即可。

Code

https://atcoder.jp/contests/abc294/submissions/40106344

#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <queue>

using namespace std;


int n, q;
priority_queue<int, vector<int>, greater<int> > wait;
set<int> called;

int main(){
    cin >> n >> q;
    
    for(int i=1; i<=n; i++){
        wait.push(i);
    }
    
    for(int i=0; i<q; i++){
        int e;
        cin >> e;
        
        if (e == 1){
            if (!wait.empty()){
                int smallest = wait.top();
                wait.pop();

                called.insert(smallest);
            }
        } else if (e == 2){
            int x;
            cin >> x;
            
            if (called.count(x) > 0){
                called.erase(x);
            }
        } else if (e == 3) {
            if (called.size() > 0){
                cout << *called.begin() << endl;
            }
        }
    }
}

 

标签:abc294,int,wait,include,called,Bank,取钱者
From: https://www.cnblogs.com/lightsong/p/17263127.html

相关文章