B. Tea Queue codeforces Round.37.div2 队列
1 second
256 megabytes
standard input
standard output
Recently n students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
i-th student comes to the end of the queue at the beginning of li-th second. If there are multiple students coming to the queue in the same moment, then the student with greater index comes after the student with lesser index. Students in the queue behave as follows: if there is nobody in the queue before the student, then he uses the teapot for exactly one second and leaves the queue with his tea; otherwise the student waits for the people before him to get their tea. If at the beginning of ri-th second student i still cannot get his tea (there is someone before him in the queue), then he leaves the queue without getting any tea.
For each student determine the second he will use the teapot and get his tea (if he actually gets it).
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 1000).
Then t test cases follow. The first line of each test case contains one integer n (1 ≤ n ≤ 1000) — the number of students.
Then n lines follow. Each line contains two integer li, ri (1 ≤ li ≤ ri ≤ 5000) — the second i-th student comes to the end of the queue, and the second he leaves the queue if he still cannot get his tea.
It is guaranteed that for every condition li - 1 ≤ li holds.
The sum of n over all test cases doesn't exceed 1000.
Note that in hacks you have to set t = 1.
For each test case print n integers. i-th of them must be equal to the second when i-th student gets his tea, or 0 if he leaves without tea.
2
2
1 3
1 4
3
1 5
1 1
2 3
1 2
1 0 2
The example contains 2 tests:
- During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second.
- During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and gets his tea.
给你n个人进队的顺序和出队的顺序,每秒的时候排在最前面的人可以取到茶,问每个人取茶的时间。
注意逻辑顺序,如果轮到的人这秒要离开他会先取到茶再离开
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
typedef long long ll;
struct node {
int id,l;
};
bool cmp( node x, node y ) {
if( x.l == y.l ) {
return x.id < y.id;
}
return x.l < y.l;
}
int main() {
int T;
cin >> T;
while( T -- ) {
int n,R[],b[],MAX = -;
cin >> n;
node a[];
for( int i=; i<=n; i++ ) {
cin >> a[i].l >> R[i];
a[i].id = i;
MAX = max(MAX,R[i]);
b[i] = ;
}
sort( a+, a+n+, cmp );
queue<int> q;
for( int i=,j=; i<=MAX; i++ ) {
while( j <= n && a[j].l == i ) {
q.push(a[j++].id);
}
while( !q.empty() && R[q.front()] < i ) {
q.pop();
}
if( !q.empty() ) {
b[q.front()] = i;
q.pop();
}
}
for( int i=; i<=n; i++ ) {
cout << b[i] << " ";
}
cout << endl;
}
return ;
}
B. Tea Queue codeforces Round.37.div2 队列的更多相关文章
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
- Codeforces Round #564(div2)
Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- 【前行】◇第3站◇ Codeforces Round #512 Div2
[第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...
- Codeforces Round#320 Div2 解题报告
Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...
- Codeforces Round #361 div2
ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...
- Educational Codeforces Round 37 (Rated for Div. 2)
我的代码应该不会被hack,立个flag A. Water The Garden time limit per test 1 second memory limit per test 256 mega ...
- Educational Codeforces Round 37 A B C D E F
A. water the garden Code #include <bits/stdc++.h> #define maxn 210 using namespace std; typede ...
随机推荐
- 技巧:结合Zabbix与SNMP监控嵌入式设备
在如何利用Zabbix监控网络设备三篇文章的前两篇中,我们介绍了如何通过Zabbix代理监控网络设备.但有些设备无法安装Zabbix代理,需要采用其他方法监控.需要考虑无法安装软件的嵌入式设备或应用程 ...
- JavaSE之——并没有多维数组
近日在读<疯狂Java讲义>精粹第二版,部分语述摘自其中,自己边敲边理解 前言 我们知道,Java语言支持的类型有两种: 1.基本类型(即八大基本数据类 ...
- WPF后台设置颜色字体等
Button TempButton = new Button(); TempButton.Tag = “按 ...
- STM32实现Airplay音乐播放器
AirPlay是苹果公司推出的一套无线音乐解决方案,我们手里的iPhone.iPad甚至是Apple Watch等设备还有电脑上的iTunes都支持AirPlay,但是支持AirPlay功能的音响设备 ...
- Docker笔记(八):数据管理
前面(哪个前面我也忘了)有说过,如果我们需要对数据进行持久化保存,不应使其存储在容器中,因为容器中的数据会随着容器的删除而丢失,而因通过将数据存储于宿主机文件系统的形式来持久化.在Docker容器中管 ...
- 帝国CMS(EmpireCMS) v7.5 后台XSS漏洞分析
帝国CMS(EmpireCMS) v7.5 后台XSS漏洞分析 一.漏洞描述 该漏洞是由于代码只使用htmlspecialchars进行实体编码过滤,而且参数用的是ENT_QUOTES(编码双引号和单 ...
- malloc和free
1.系统使用红黑树管理空闲堆空间,malloc是申请了堆一块内存的使用权,拿到了这个钥匙,然后红黑树该块的空闲标记被去除. 2.free后,红黑树重新标记该块内存为空闲,其他程序就可以申请到此块内存. ...
- vulnhub-XXE靶机渗透
下载链接:https://download.vulnhub.com/xxe/XXE.zip 0x01 确定目标IP 目标网络模式默认为net模式,无需修改 使用arp-scan或者netdisco ...
- 运行所选代码生成器时出错:“值-1超出了可接受的[0,2147483647]范围。参数名称:value”
在使用vs2019添加mvc控制器的时候 这已经是第二次遇到这个问题了.常言道,多喝热水,重启试试.有时候当应用工作不正常,重启也许能解决问题.但是程序员通常接触不到服务器系统权限.而运维人员和公司流 ...
- com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: con ...