【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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值