使用map存下每一列的最大值与最小值
合法条件,后一列最小值大于等于前一列最大值
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int m;
cin >> m;
map<int, vector<int>>c;
string s;
while (m--) {
int x, y;
cin >> x >> y;
if (c.count(x) == 0) {
c[x].push_back(y);
c[x].push_back(y);
}
else if (c[x][1] < y) {
c[x][1] = y;
}
else if (c[x][0] > y)c[x][0] = y;
}
int tr = 0;
int tc = 0;
for (int i = 0; i < 1001; i++) {
if (c.count(i))
{
while (i - tr) {
s += "R";
tr++;
}
if (c[i][0] < tc) {
cout << "NO" << endl;
goto w;
}
while (c[i][1] - tc)
{
s += "U";
tc++;
}
}
}
cout << "YES" << endl;
cout << s << endl;
w:;
}
}