#P2239. [NOIP 2014 普及组] 螺旋矩阵
[NOIP 2014 普及组] 螺旋矩阵
Description
A spiral matrix with rows and columns can be generated as follows:
Starting from the top-left corner (row , column ), initially move to the right. If the cell ahead has not been visited, keep moving forward; otherwise, turn right. Repeat this process until all cells in the matrix have been visited. According to the visiting order, fill the cells with in sequence to form a spiral matrix.
Below is the spiral matrix when .
$$\begin{pmatrix} 1 & 2 & 3 & 4 \\ 12 & 13 & 14 & 5 \\ 11 & 16 & 15 & 6 \\ 10 & 9 & 8 & 7 \\ \end{pmatrix}$$Given the matrix size and and , please compute the number at row , column in this matrix.
Input Format
A single line containing three integers , , , separated by a single space. They represent the matrix size, and the row and column of the number to query.
Output Format
A single integer, the number at row , column in the corresponding matrix.
4 2 3
14
Hint
Constraints
- For of the testdata, .
- For of the testdata, ; ; .
Translated by ChatGPT 5
京公网安备 11011102002149号