9125: Puzzle: Star Battle

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Grammy is a puzzle master. Today, she is playing a variant of "Star Battle" puzzle.

The puzzle consists of a (4n)×(4n)(4n) \times (4n)(4n)×(4n) grid. The grid is divided into 4n4n4n blocks, but each block may be disconnected. The goal is to place stars into the grid so that each row, each column, and each block contains exactly nnn stars. Additionally, two stars cannot be adjacent, diagonally or orthogonally. In other words, two stars cannot be placed in two cells that share an edge or a corner.



The left picture illustrates a 4×44\times 44×4 empty puzzle, and the right picture shows a solution to the puzzle.

Grammy surely knows how to solve the puzzle, but she decided to give you a quiz. Please solve the puzzle.

输入格式

The first line contains a single integer nnn (1≤n≤3001 \leq n \leq 3001n300), denoting the number of stars to place in each row.
Each of the following 4n4n4n lines contains 4n4n4n integers grcg_{rc}grc (1≤grc≤4n1 \leq g_{rc} \leq 4n1grc4n), denoting the index of the block which the cell (at row rrr, column ccc) belongs to. It is guaranteed that each block contains at least one cell. However, it is not guaranteed that each block is an orthogonally connected region.

输出格式

If the solution does not exist, output "NO\texttt{NO}NO" on a single line.
Otherwise, output "YES\texttt{YES}YES" on the first line, then output 4n24n^24n2 lines, each of which contains 222 integers r,cr,cr,c (1≤r,c≤4n1\leq r,c \leq 4n1r,c4n), denoting the coordinates (row rrr, column ccc) of each placed star.
If there are multiple solutions, output any.

输入样例 复制

1
1 2 2 2
1 2 2 4
3 4 4 4
3 3 3 4

输出样例 复制

YES
1 3
2 1
3 4
4 2

分类标签