Luo Valley 2239
• the meaning of problems
The upper left corner (the matrix 1 1 Row 1 Column 1) starting an initial rightward movement;
If the front is not been through the grid, then move on, otherwise turn right;
Repeat until all the lattice through the matrix.
The sequence passes, sequentially filled in the lattice $ 1,2,3 ... n $ constitute a spiral matrix
Now given matrix size $ n $ and $ i $ and $ J $ , you find the matrix $ (i, j) $ number is the number.
• ideas
This is mainly $ O (1) $ records about the idea, in order to prevent forgetting to focus on the record about
① calculated the number of laps:
From the center of the entire matrix can be divided into four parts, namely the upper left, upper right, lower left, lower right
Three other small matrices can be symmetric to the upper left matrix,
Why is it the upper left matrix, because from (1,1) to start making their $ x, y $ coordinate in line with $ min (x, y) = $ laps
After obtaining a few laps to find a location based on the number of turns is more relaxed
Easy to find
Number of digits of the first lap circled number 2 digits number of the third ring ... ring of $ X $ digits
$ 4 (n-1) $ $ 4 (n-3) $ $ 4 (n-5) $ ... $ 4 (n-2x + 1) $
Then observe the first position of each ring
$(1,1) \ ,\ (2,2) \ ,\ (3,3),....$
It can be observed before the $ 1/2 $ two (upper half) of each turn of the spiral with a number of matrix, $ (x + y) $ 1 $ $ increases, as shown