No.1384 Bishop and Rook
Problem Statement
There is a grid of $\ N \times M\ $ cells.
Let $\ (i,j)\ $ denote the cell in the $\ i\ $-th row from the top and the $\ j\ $-th column from the left.
You currently have $\ 1\ $ stone, and you place it on any cell you like.
After that, you repeat the following operations $\ 1,2\ $ in the order of operations $\ 1,2,1,2,\cdots\ $, starting from operation $\ 1\ $, and end the process at any time you like.
However, if an operation cannot be performed, the process ends at that point. Note also that it is fine not to perform even $1$ operation.
Operation $\ 1 : $ Move the stone to a cell that shares $\ 1\ $ vertex with the cell where the stone is currently placed, and place the stone on that cell.
(Strictly speaking, move the stone from $\ (i,j)\ $ to one of $\ (i-1,j-1),(i-1,j+1),(i+1,j-1),(i+1,j+1)\ $; however, the stone must not leave the grid.)
Operation $\ 2 : $ Move the stone to a cell that shares $\ 1\ $ edge with the cell where the stone is currently placed, and place the stone on that cell.
(Strictly speaking, move the stone from $\ (i,j)\ $ to one of $\ (i-1,j),(i,j-1),(i,j+1),(i+1,j)\ $; however, the stone must not leave the grid.)
If, at the time you end the process, a stone has been placed on every cell exactly $\ 1\ $ time each, Mitsubachi-kun will be pleased.
Note that when you first place the stone on a cell, that cell is also considered to have had a stone placed on it.
Is there a way to choose the initial position of the stone and perform the operations so that Mitsubachi-kun will be pleased?
If one exists, report how to choose the position of the stone and how to perform the operations; if none exists, report that fact.
If there are multiple ways to choose the initial position of the stone and perform the operations so that Mitsubachi-kun will be pleased, any of them will be accepted.
You are given $\ T\ $ test cases; find the answer for each of them.
Input
The $\ 1\ $st line of the input is as follows.$T$Then, $\ T\ $ test cases follow. Each of them is given in the following format.
$N\ \ M$
- $1 \leq T \leq 100$
- $1 \leq N,M \leq 1000$
- For each input file, the sum of the maximum of $\ N\ $ and $\ M\ $ over the given test cases does not exceed $\ 1200\ $.
- All inputs are integers.
Output
If there is no way to choose the position of the stone and perform the operations so that Mitsubachi-kun will be pleased, print -1 followed by a newline.
Otherwise, output as follows.
$Q$
$s\ \ t$
$i_1\ \ j_1$
$i_2\ \ j_2$
$\vdots$
$i_Q\ \ j_Q$
Here, $\ Q\ $ represents the total number of operations $\ 1,2\ $.
Also, $\ s,t\ $ indicate that the cell where the stone is first placed is $\ (s,t)\ $, and $i_k,j_k(1 \leq k \leq Q)\ $ indicate that the stone is placed on $\ (i_k,j_k)\ $ after repeating operations $\ 1,2\ $ a total of $\ k\ $ times.
Therefore, your output must satisfy the following constraints.
- $0 \leq Q$
- $1 \leq s,i_k \leq N(1 \leq k \leq Q)$
- $1 \leq t,j_k \leq M(1 \leq k \leq Q)$
- All outputs are integers.
In this case, the output consists of $\ Q+2\ $ lines in total. Also, print a newline at the end.
Do this for all $\ T\ $ test cases.
Sample
Sample 1
Input
2
2 2
1 3
Output
3
1 2
2 1
2 2
1 1
-1
The output for the $\ 1\ $st test case means that the stone is placed on $\ (1,2)\ $, and operations $\ 1,2,1\ $ are performed in this order, moving the stone through $\ (2,1),(2,2),(1,1)\ $.
The following output for the $\ 1\ $st test case is also accepted.
3On the other hand, the following outputs for the $\ 1\ $st test case are not accepted.
1 1
2 2
2 1
1 2
3
1 1
1 2
2 1
2 2
4The $\ 1\ $st output starts with operation $\ 2\ $. In the $\ 2\ $nd output, a stone is placed on $\ (1,2)\ $ $\ 2\ $ times.
1 2
2 1
2 2
1 1
1 2
For the $\ 2\ $nd test case, wherever the stone is placed, operation $\ 1\ $, which is to be performed as the $\ 1\ $st operation, cannot be performed, so the process ends.
In this case, a stone has been placed $\ 1\ $ time on only $\ 1\ $ cell, so Mitsubachi-kun is not pleased.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂