当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5493:Queue

题目描述
$N$ people numbered from 1 to $N$ are waiting in a bank for service. They all stand in a queue, but the queue never moves. It is lunch time now, so they decide to go out and have lunch first. When they get back, they don’t remember the exact order of the queue. Fortunately, there are some clues that may help.
Every person has a unique height, and we denote the height of the $i$-th person as $h_i$. The $i$-th person remembers that there were $k_i$ people who stand before him and are taller than him. Ideally, this is enough to determine the original order of the queue uniquely. However, as they were waiting for too long, some of them get dizzy and counted $k_i$ in a wrong direction. $k_i$ could be either the number of taller people before or after the $i$-th person.
Can you help them to determine the original order of the queue?
输入解释
The first line of input contains a number $T$ indicating the number of test cases ($T≤1000$).
Each test case starts with a line containing an integer $N$ indicating the number of people in the queue ($1≤N≤100000$). Each of the next $N$ lines consists of two integers $h_i$ and $k_i$ as described above ($1≤h_i≤10^9,0≤k_i≤N-1$). Note that the order of the given $h_i$ and $k_i$ is randomly shuffled.
The sum of $N$ over all test cases will not exceed $10^6$
输出解释
For each test case, output a single line consisting of “Case #X: S”. $X$ is the test case number starting from 1. $S$ is people’s heights in the restored queue, separated by spaces. The solution may not be unique, so you only need to output the smallest one in lexicographical order. If it is impossible to restore the queue, you should output “impossible” instead.
输入样例
3
3
10 1
20 1
30 0
3
10 0
20 1
30 0
3
10 0
20 0
30 1
输出样例
Case #1: 20 10 30
Case #2: 10 20 30
Case #3: impossible
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5493

最后修改于 2020-10-25T23:23:09+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 65536/65536K(Java/Others)