CF1294B.Collecting Packages
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0,0). The i-th package is at the point (xi,yi). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0) doesn't contain a package.
The robot is semi-broken and only can move up ('U') and right ('R'). In other words, in one move the robot can go from the point (x,y) to the point (x+1,y) or to the point (x,y+1).
As we say above, the robot wants to collect all n packages (in arbitrary order). He wants to do it with the minimum possible number of moves. If there are several possible traversals, the robot wants to choose the lexicographically smallest path.
The string s of length n is lexicographically less than the string t of length n if there is some index 1≤j≤n that for all i from 1 to j−1 si=ti and sj<tj. It is the standard comparison of string, like in a dictionary. Most programming languages compare strings in this way.
仓库中有一个机器人,需要收集 n 个包裹。仓库可表示为一个坐标网格。初始时,机器人位于点 (0,0)。第 i 个包裹位于点 (xi,yi)。保证不存在两个包裹位于同一点;同时也保证点 (0,0) 上没有包裹。
该机器人处于半损坏状态,仅能向上('U')或向右('R')移动。换言之,每次移动中,机器人可以从点 (x,y) 移动到点 (x+1,y) 或点 (x,y+1)。
如前所述,机器人希望以任意顺序收集全部 n 个包裹,并希望总移动步数尽可能少。若存在多种满足最少步数的路径,则机器人希望选择字典序最小的路径。
长度为 n 的字符串 s 在字典序上小于长度为 n 的字符串 t,当且仅当存在某个下标 1≤j≤n,使得对所有 i=1,2,…,j−1 均有 si=ti,且 sj<tj。这是标准的字符串字典序比较方式(如同查字典),大多数编程语言均采用此方式比较字符串。
输入格式
The first line of the input contains an integer t (1≤t≤100) — the number of test cases. Then test cases follow.
The first line of a test case contains one integer n (1≤n≤1000) — the number of packages.
The next n lines contain descriptions of packages. The i-th package is given as two integers xi and yi (0≤xi,yi≤1000) — the x-coordinate of the package and the y-coordinate of the package.
It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0) doesn't contain a package.
The sum of all values n over test cases in the test doesn't exceed 1000.
输入的第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是各测试用例。
每个测试用例的第一行包含一个整数 n(1≤n≤1000),表示包裹的数量。
接下来的 n 行描述了各个包裹。第 i 个包裹由两个整数 xi 和 yi(0≤xi,yi≤1000)给出,分别表示该包裹的 x 坐标和 y 坐标。
保证不存在两个包裹位于同一点;同时也保证点 (0,0) 上没有包裹。
所有测试用例中 n 的总和不超过 1000。
输出格式
Print the answer for each test case.
If it is impossible to collect all n packages in some order starting from (0,0), print "NO" on the first line.
Otherwise, print "YES" in the first line. Then print the shortest path — a string consisting of characters 'R' and 'U'. Among all such paths choose the lexicographically smallest path.
Note that in this problem "YES" and "NO" can be only uppercase words, i.e. "Yes", "no" and "YeS" are not acceptable.
对每个测试用例,输出答案。
如果从 (0,0) 出发以某种顺序收集全部 n 个包裹是不可能的,则在第一行输出 "NO"。
否则,在第一行输出 "YES";然后输出最短路径——一个仅由字符 'R' 和 'U' 组成的字符串。在所有这样的最短路径中,选择字典序最小的路径。
注意:本题中 "YES" 和 "NO" 必须严格为大写字母,即 "Yes"、"no" 和 "YeS" 等均不可接受。
输入输出样例
输入#1
3 5 1 3 1 2 3 3 5 5 4 3 2 1 0 0 1 1 4 3
输出#1
YES RUUURRRRUU NO YES RRRRUUU
说明/提示
For the first test case in the example the optimal path RUUURRRRUU is shown below:

对于示例中的第一个测试用例,最优路径 RUUURRRRUU 如下图所示:

输入解题思路,AI测评打分。不知道怎么写?