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;
}
- Extjs form 组件
- Extjs grid 组件
- WordPress 网站开发“微信小程序”实战(三)
- Extjs mvc
- Extjs 数据代理
- WordPress 网站开发“微信小程序”实战(四)
- 详解零知识证明的四大基础技术,如何与以太坊发生反应
- 入门:添加一个支持获取单一资源以及支持POST,PUT和DELETE方法
- html5语义化标签——回顾
- flex布局——回顾
- WordPress 网站开发“微信小程序”实战(五)
- Windows Runtime(WinRT) 揭秘
- WeApp-Workflow: 基于Gulp 的微信小程序前端开发工作流
- 如何安装Windows Phone SDK 7.1 Release Candidate (RC)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 代码审计从0到1 —— Centreon One-click To RCE
- 一文带你深扒ClassLoader内核,揭开它的神秘面纱!
- 小知识:OGG的TRANLOGOPTIONS MINEFROMACTIVEDG参数
- oracle转postgreSQL修改点
- 重学数据结构(三、队列)
- Jmeter系列(68)- BeanShell 内置变量 prev
- 聊聊java中的哪些Map:(六)ConcurrentHashMap源码分析
- 任意文件包含漏洞的绕过方式
- XXE实体注入漏洞详解
- ent orm笔记2---schema使用(下)
- 零基础Python教程043期 列表的增删改查,彻底学通序列基本操作
- MySQL与JDBC精简笔记
- Ajax的使用
- 时间复杂度与空间复杂度
- 零基础Python教程042期 求最值?求存在性?非常实用!