Codeforces Round #615 (Div. 3)B. Collecting Packages

时间:2022-07-26
本文章向大家介绍Codeforces Round #615 (Div. 3)B. Collecting Packages,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

B. Collecting Packages

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a robot in a warehouse and nn packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0,0)(0,0). The ii-th package is at the point (xi,yi)(xi,yi). It is guaranteed that there are no two packages at the same point. It is also guaranteed that the point (0,0)(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)(x,y) to the point (x+1,yx+1,y) or to the point (x,y+1)(x,y+1).

As we say above, the robot wants to collect all nn 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 ss of length nn is lexicographically less than the string tt of length nn if there is some index 1≤j≤n1≤j≤n that for all ii from 11 to j−1j−1 si=tisi=ti and sj<tjsj<tj. It is the standard comparison of string, like in a dictionary. Most programming languages compare strings in this way.

Input

The first line of the input contains an integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then test cases follow.

The first line of a test case contains one integer nn (1≤n≤10001≤n≤1000) — the number of packages.

The next nn lines contain descriptions of packages. The ii-th package is given as two integers xixi and yiyi (0≤xi,yi≤10000≤xi,yi≤1000) — the xx-coordinate of the package and the yy-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)(0,0) doesn't contain a package.

The sum of all values nn over test cases in the test doesn't exceed 10001000.

Output

Print the answer for each test case.

If it is impossible to collect all nn packages in some order starting from (0,00,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.

Example

input

Copy

3
5
1 3
1 2
3 3
5 5
4 3
2
1 0
0 1
1
4 3

output

Copy

YES
RUUURRRRUU
NO
YES
RRRRUUU

Note

For the first test case in the example the optimal path RUUURRRRUU is shown below:

B. Collecting Packages

题目链接:https://codeforces.com/contest/1294/problem/B

题意:

有n个盒子需要你捡,第i个盒子的坐标为 (Xi , Yi)。你从(0,0)出发,每次只能选择向上或者向右移动,问能否将n个盒子都捡完,若可以捡完,则输出字典序最小的一条路线

首先理解字典序最小,往右走是R,往上走是U,R的字典序比U前面,所以如果可以往右走和往上走要先往右走再往上走

这样我们就很自然的对每一个坐标对按x从小到大排序,然后如果上一个盒子的y坐标比下一个大,那么gg直接输出no,

所以得先预检查一遍,如果没有这种情况的存在就ok,然后每次先往右走i+1个盒子的横坐标减i个盒子的横坐标,然后往上走i+1个盒子的纵坐标减i个盒子的纵坐标

#include<bits/stdc++.h>
#define ll long long
#define rg register ll
using namespace std;
ll n,t;
struct node
{
    ll x,y;
    bool operator <(const node& a)const{
        if(x==a.x)return y<a.y;
        return x<a.x;
    }
}p[1005];
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(rg i=1;i<=n;i++)
        {
            cin>>p[i].x>>p[i].y;
        }
        sort(p+1,p+1+n);
        ll tepx=0,tepy=0,flag=0;
        for(rg i=1;i<=n;i++)
        {
            if(p[i].y<p[i-1].y)
            {
                flag=1;
                break;
            }   
        }
        if(flag)cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            for(rg i=1;i<=n;i++)
            {
                for(rg j=1;j<=p[i].x-tepx;j++)cout<<"R";
                tepx=p[i].x;
                for(rg j=1;j<=p[i].y-tepy;j++)cout<<"U";
                tepy=p[i].y;
            }
            cout<<endl;
        }
        
    }

    while(1)getchar();
    return 0;
}