#P10578. [蓝桥杯 2024 国 A] 旋转九宫格
[蓝桥杯 2024 国 A] 旋转九宫格
Problem Description
Given a grid, each cell contains a number, and all numbers in the grid are distinct. In each step, we may choose any sub-square and rotate it clockwise, for example:
1 2 3
4 5 6
7 8 9
If we rotate the top-right sub-square, we get:
1 5 2
4 6 3
7 8 9
Find the minimum number of steps needed to rotate the given state into
1 2 3
4 5 6
7 8 9
Input Format
The first line contains an integer , the number of queries.
Then follow queries.
Each query consists of three lines, each containing three numbers, describing the current state of the grid.
Output Format
Output lines. Each line contains one integer, the answer for that query.
2
1 2 3
4 5 6
7 8 9
1 5 2
4 6 3
7 8 9
0
3
Hint
For of the testdata, .
For all testdata, .
Translated by ChatGPT 5