#1039. 【入门4】方块转换

【入门4】方块转换

说明

一块 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi><mo>×</mo><mi>�</mi></mrow></semantics></math>n×n 正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:

  • 转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>90</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>90°:图案按顺时针转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>90</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>90°

  • 转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>180</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>180°:图案按顺时针转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>180</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>180°

  • 转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>270</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>270°:图案按顺时针转 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>270</mn><mi mathvariant="normal">°</mi></mrow></semantics></math>270°

  • 反射:图案在水平方向翻转(以中央铅垂线为中心形成原图案的镜像)。

  • 组合:图案在水平方向翻转,然后再按照 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>∼</mo><mn>3</mn></mrow></semantics></math>13 之间的一种再次转换。

  • 不改变:原图案不改变。

  • 无效转换:无法用以上方法得到新图案。

如果有多种可用的转换方法,请选择序号最小的那个。

只使用上述 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>7</mn></mrow></semantics></math>7 个中的一个步骤来完成这次转换。

输入格式

第一行一个正整数 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi></mrow></semantics></math>n

然后 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi></mrow></semantics></math>n 行,每行 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi></mrow></semantics></math>n 个字符,全部为 @ 或 -,表示初始的正方形。

接下来 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi></mrow></semantics></math>n 行,每行 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>�</mi></mrow></semantics></math>n 个字符,全部为 @ 或 -,表示最终的正方形。

输出格式

单独的一行包括 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>∼</mo><mn>7</mn></mrow></semantics></math>17 之间的一个数字(在上文已描述)表明需要将转换前的正方形变为转换后的正方形的转换方法。

样例

3
@-@
---
@@-
@-@
@--
--@
1

提示

数据范围:

对于 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>100</mn><mi mathvariant="normal">%</mi></mrow></semantics></math>100% 的数据,<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>≤</mo><mi>�</mi><mo>≤</mo><mn>10</mn></mrow></semantics></math>1n10

题目翻译来自 NOCOW。

USACO Training Section 1.2