M-SOLUTIONS プロコンオープン2021(AtCoder Beginner Contest 232)
H
King's Tour
AtCoder
⌀ 2780
原题
← G→
翻译中…

Problem Statement

翻译中…

We have an $H \times W$ chessboard with $H$ rows and $W$ columns, and a king. Let $(i, j)$ denote the square at the $i$-th row from the top $(1 \leq i \leq H)$ and $j$-th column from the left $(1 \leq j \leq W)$. The king can move one square in any direction. Formally, the king on $(i,j)$ can move to $(k,l)$ if and only if $\max(|i-k|,|j-l|) = 1$.

翻译中…

A tour is the process of moving the king on the $H \times W$ chessboard as follows.

翻译中…
  • Start by putting the king on $(1, 1)$. Then, move the king to put it on each square exactly once.
翻译中…

For example, when $H = 2, W = 3$, going $(1,1) \to (1,2) \to (1, 3) \to (2, 3) \to (2, 2) \to (2, 1)$ is a valid tour.

翻译中…

You are given a square $(a, b)$ other than $(1, 1)$. Construct a tour ending on $(a,b)$ and print it. It can be proved that a solution always exists under the Constraints of this problem.

翻译中…

Constraints

翻译中…
  • $2 \leq H \leq 100$
  • $2 \leq W \leq 100$
  • $1 \leq a \leq H$
  • $1 \leq b \leq W$
  • $(a, b) \neq (1, 1)$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

H W a b

翻译中…

Output

翻译中…

Print $HW$ lines. The $i$-th line should contain the $i$-th square $(h_i, w_i)$ the king is put on, in the following format:

翻译中…

h_i w_i

翻译中…

Here, note that the $1$-st line should contain $(1, 1)$, and the $HW$-th line should contain $(a, b)$.

翻译中…

样例

Input #1
3 2 3 2
Output #1
1 1
1 2
2 1
2 2
3 1
3 2
The king goes $(1, 1) \to (1, 2) \to (2, 1) \to (2, 2)\to (3, 1) \to (3, 2)$, which is indeed a tour ending on $(3, 2)$. There are some other valid tours, three of which are listed below. - $(1, 1) \to (1, 2) \to (2, 2) \to (2, 1) \to (3, 1) \to (3, 2)$ - $(1, 1) \to (2, 1) \to (1, 2) \to (2, 2) \to (3, 1) \to (3, 2)$ - $(1, 1) \to (2, 2) \to (1, 2) \to (2, 1) \to (3, 1) \to (3, 2)$
题目信息
题号
abc232_h
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。