#15775. [SDCPC 2023] Puzzle: Sashigane

    ID: 15775 传统题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P95672023山东Special JudgeO2优化构造省赛/邀请赛

[SDCPC 2023] Puzzle: Sashigane

[SDCPC 2023] Puzzle: Sashigane

题目描述

Given a grid with $n$ rows and $n$ columns, there is exactly one black cell in the grid and all other cells are white. Let $(i, j)$ be the cell on the $i$-th row and the $j$-th column, this black cell is located at $(b_i, b_j)$.

You need to cover all white cells with some L-shapes, so that each white cell is covered by exactly one L-shape and the only black cell is not covered by any L-shape. L-shapes must not exceed the boundary of the grid.

More formally, an L-shape in the grid is uniquely determined by four integers (r,c,h,w)(r, c, h, w), where (r,c)(r, c) determines the turning point of the L-shape, and hh and ww determine the direction and lengths of the two arms of the L-shape. The four integers must satisfy 1≤r,c≤n1 \le r, c \le n, 1≤r+h≤n1 \le r + h \le n, 1≤c+w≤n1 \le c + w \le n, h≠0h \ne 0, w≠0w \ne 0.

  • If h<0h < 0, then all cells (i,c)(i, c) satisfying r+h≤i≤rr + h \le i \le r belong to this L-shape; Otherwise if h>0h > 0, all cells (i,c)(i, c) satisfying r≤i≤r+hr \le i \le r + h belong to this L-shape.
  • If w<0w < 0, then all cells (r,j)(r, j) satisfying c+w≤j≤cc + w \le j \le c belong to this L-shape; Otherwise if w>0w > 0, all cells (r,j)(r, j) satisfying c≤j≤c+wc \le j \le c + w belong to this L-shape.

The following image illustrates some L-shapes.

输入格式

There is only one test case in each test file.

The first line contains three integers nn, bib_i and bjb_j (1≤n≤1031 \le n \le 10^3, 1≤bi,bj≤n1 \le b_i, b_j \le n) indicating the size of the grid and the position of the black cell.

输出格式

If a valid answer exists first output `Yes` in the first line, then in the second line output an integer $k$ ($0 \leq k \leq \frac{n^2-1}{3}$) indicating the number of L-shapes to cover white cells. Then output $k$ lines where the $i$-th line contains four integers $r_i$, $c_i$, $h_i$, $w_i$ separated by a space indicating that the $i$-th L-shape is uniquely determined by $(r_i, c_i, h_i, w_i)$. If there are multiple valid answers you can print any of them.

If there is no valid answer, just output No in one line.

5 3 4
Yes
6
5 1 -1 3
1 2 1 3
3 1 -2 1
4 3 -1 -1
4 5 1 -1
2 5 1 -2
1 1 1
Yes
0

提示

We illustrate the first sample test case as follows.

标签: P9567|2023|山东|Special Judge|O2优化|构造|省赛/邀请赛

来源

P9567|[SDCPC 2023] Puzzle: Sashigane