#P1205. Square Tile Pattern Transformation
Square Tile Pattern Transformation
Square Tile Pattern Transformation
You are given an \(n \times n\) square pattern of black and white tiles and a target pattern. Your task is to determine the minimal transformation operation from the list below that converts the original pattern to the target pattern using exactly one transformation.
The allowed transformations are:
- \(90^{\circ}\) Rotation: Rotate the original pattern clockwise by \(90^{\circ}\).
- \(180^{\circ}\) Rotation: Rotate the original pattern clockwise by \(180^{\circ}\).
- \(270^{\circ}\) Rotation: Rotate the original pattern clockwise by \(270^{\circ}\).
- Reflection: Reflect the original pattern horizontally (mirror image about its vertical central axis).
- Combination: First reflect the original pattern horizontally, then apply one of the rotations \(90^{\circ}\), \(180^{\circ}\), or \(270^{\circ}\) to the reflected pattern.
- No Change: The original pattern is identical to the target pattern.
- Invalid Transformation: None of the above operations yields the target pattern.
If multiple transformations can produce the target pattern, output the one with the smallest number.
inputFormat
The first line contains an integer \(n\) (\(1 \le n \le 10\) for example), representing the size of the square pattern. This is followed by \(n\) lines, each containing a string of exactly \(n\) characters ('B' or 'W') representing the original pattern. After that, there are another \(n\) lines representing the target pattern in the same format.
outputFormat
Output a single integer from 1 to 7 that indicates the minimal transformation operation needed to convert the original pattern into the target pattern.
sample
3
BWW
WBB
BWB
BWB
WBW
BBW
1