QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#1166. 设计 PCB

Estadísticas

Dongkyu 正在尝试设计一块单面印刷电路板(简称 PCB)。PCB 由可以安装元件的焊盘以及连接焊盘的导电轨道组成。你可以将 PCB 想象成一个无限的二维平面,焊盘是平面上的点,轨道是平面上的连通折线。

在 Dongkyu 想要设计的电路中,$2n$ 个焊盘水平排列。从左侧数第 $i$ 个焊盘位于坐标 $(i - 1, 0)$ 处。每个焊盘都被分配了一个标签:一个介于 $1$ 到 $n$ 之间的整数(包含 $1$ 和 $n$)。对于每个 $1 \le i \le n$,恰好有两个焊盘的标签为 $i$。

Dongkyu 需要绘制 $n$ 条轨道来连接标签相同的焊盘对。每条轨道必须是由长度为正整数的线段组成的折线,且每条线段都平行于坐标轴之一。轨道起始于并终止于代表焊盘的点。任意两条轨道不得共享公共点。

给定焊盘的数量和标签,编写一个程序来设计该电路。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 1000$)。

第二行包含 $2n$ 个整数 $p_i$ ($1 \le p_i \le n$)。其中 $p_i$ 是从左侧数第 $i$ 个焊盘的标签。

保证 $1$ 到 $n$ 之间的每个整数在标签中恰好出现两次。

输出格式

如果无法设计出符合题目描述限制的电路,输出 “NO”。

否则,第一行输出 “YES”。接下来的 $n$ 行,按照连接焊盘的标签从小到大的顺序,输出 $n$ 条轨道的描述。

每条轨道必须是从两个连接焊盘中靠左的那一个开始的折线。轨道描述以一个整数 $L_i$ ($1 \le L_i \le 10$) 开头,表示构成该轨道的线段数量。每条线段由一个表示方向的字母和一个表示线段长度的正整数描述。方向为:‘D’ — 下($y$ 减小),‘U’ — 上($y$ 增加),‘R’ — 右($x$ 增加),以及 ‘L’ — 左($x$ 减小)。线段必须按照它们连接的顺序,从起始焊盘列出到结束焊盘。

每条折线不得自交或自接触。不同的折线不得有公共点。折线顶点的坐标绝对值不得超过 $10^4$。字母和整数之间用空格分隔。请查看样例输出以明确格式。

如果存在多种方案,接受其中任意一种即可。

样例

样例输入 1

4
1 2 3 4 1 2 3 4

样例输出 1

YES
3 U 1 R 4 D 1
5 D 1 L 2 U 3 R 6 D 2
5 D 2 R 6 U 3 L 2 D 1
3 D 1 R 4 U 1

样例输入 2

4
1 2 3 4 1 3 2 4

样例输出 2

NO

说明

样例 1 的一种可能电路如上图所示。在样例 2 中,我们无法在不使不同轨道相交的情况下连接焊盘。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.