【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;
}
posted @ 2018-02-03 10:17  AWCXV  阅读(172)  评论(0编辑  收藏  举报