zoukankan      html  css  js  c++  java
  • 【Educational Codeforces Round 37 B】 Tea Queue

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    用一个队列来模拟排队就好。 队列放三元组(x,y,z) x表示人的下标,y和z分别表示进入和退出时间。 然后枚举时间从1到5000 看看有没有人在这个时刻入队。 有的话就入队。 入完之后。 再处理在队头的人。 如果已经超过了最晚时间,就找队列的下一个。

    【代码】

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 1000;
    
    int n;
    vector<pair<int,int> > v;
    queue<pair<int,pair<int,int> > > dl;
    int ans[N+10];
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
        int T;
        cin >> T;
        while (T--){
            memset(ans,0,sizeof ans);
            while (!dl.empty()) dl.pop();
            cin >> n;
            v.clear();
            for (int i = 1;i <= n;i++){
                int x,y;
                cin >> x >> y;
                v.push_back({x,y});
            }
    
            for (int now = 1,j = 0;now <= 5000;now++){
                while(j<n && v[j].first==now){
                    dl.push({j+1,{v[j].first,v[j].second}});
                    j++;
                }
                while (!dl.empty()){
                    auto temp = dl.front();
                    dl.pop();
                    if (temp.second.second<now){
                        continue;
                    }
                    ans[temp.first] = now;
                    break;
                }
            }
    
            for (int i = 1;i <= n;i++)
                cout<<ans[i]<<' ';
            cout<<endl;
        }
    	return 0;
    }
    
  • 相关阅读:
    Python中的memoryview
    Python常见陷阱
    特殊方法 之 len __repr__ __str__
    collections模块
    使用math中的hypot实现向量
    Ellipsis对象
    array
    标准库heapq的使用
    Mysql常用命令
    使用npm查看安装的包
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8408725.html
Copyright © 2011-2022 走看看