309590: CF1703E. Mirror Grid

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:8 Solved:0

Description

Mirror Grid

题意翻译

给定一个 $n\times n\ (n\le100)$ 的 01 矩形,求至少修改多少次后能使矩形旋转 0°,90°,180°,270°后所形成的矩形都完全相同。

题目描述

You are given a square grid with $ n $ rows and $ n $ columns. Each cell contains either $ 0 $ or $ 1 $ . In an operation, you can select a cell of the grid and flip it (from $ 0 \to 1 $ or $ 1 \to 0 $ ). Find the minimum number of operations you need to obtain a square that remains the same when rotated $ 0^{\circ} $ , $ 90^{\circ} $ , $ 180^{\circ} $ and $ 270^{\circ} $ . The picture below shows an example of all rotations of a grid. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1703E/df4a9e7a944efc8b4d2d665fb77f2a0392653bc5.png)

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \leq t \leq 100 $ ) — the number of test cases. The first line of each test case contains a single integer $ n $ ( $ 1 \leq n \leq 100 $ ) — the size of the grid. Then $ n $ lines follow, each with $ n $ characters $ a_{i,j} $ ( $ 0 \leq a_{i,j} \leq 1 $ ) — the number written in each cell.

输出格式


For each test case output a single integer — the minimum number of operations needed to make the square look the same rotated $ 0^{\circ} $ , $ 90^{\circ} $ , $ 180^{\circ} $ and $ 270^{\circ} $ .

输入输出样例

输入样例 #1

5
3
010
110
010
1
0
5
11100
11011
01011
10011
11000
5
01000
10101
01010
00010
01001
5
11001
00000
11111
10110
01111

输出样例 #1

1
0
9
7
6

说明

In the first test case, we can perform one operations to make the grid $ \begin{matrix}0 & 1 & 0\\ 1 & 1 & \color{red}{1}\\ 0 & 1 & 0\end{matrix} $ . Now, all rotations of the square are the same. In the second test case, all rotations of the square are already the same, so we don't need any flips.

Input

题意翻译

给定一个 $n\times n\ (n\le100)$ 的 01 矩形,求至少修改多少次后能使矩形旋转 0°,90°,180°,270°后所形成的矩形都完全相同。

Output

**题目大意**:

给定一个 $n \times n$ ($n \leq 100$) 的 0-1 矩阵,要求通过尽可能少的修改(0 变 1 或 1 变 0),使得矩阵旋转 0°,90°,180°,270° 后都完全相同。

**输入输出数据格式**:

- **输入格式**:
- 第一行包含一个整数 $t$ ($1 \leq t \leq 100$) — 测试用例的数量。
- 每个测试用例的第一行包含一个整数 $n$ ($1 \leq n \leq 100$) — 矩阵的大小。
- 接下来 $n$ 行,每行包含 $n$ 个字符 $a_{i,j}$ ($0 \leq a_{i,j} \leq 1$) — 每个单元格中写入的数字。

- **输出格式**:
- 对于每个测试用例,输出一个整数 — 完成旋转后使矩阵看起来相同的所需的最小操作数。**题目大意**: 给定一个 $n \times n$ ($n \leq 100$) 的 0-1 矩阵,要求通过尽可能少的修改(0 变 1 或 1 变 0),使得矩阵旋转 0°,90°,180°,270° 后都完全相同。 **输入输出数据格式**: - **输入格式**: - 第一行包含一个整数 $t$ ($1 \leq t \leq 100$) — 测试用例的数量。 - 每个测试用例的第一行包含一个整数 $n$ ($1 \leq n \leq 100$) — 矩阵的大小。 - 接下来 $n$ 行,每行包含 $n$ 个字符 $a_{i,j}$ ($0 \leq a_{i,j} \leq 1$) — 每个单元格中写入的数字。 - **输出格式**: - 对于每个测试用例,输出一个整数 — 完成旋转后使矩阵看起来相同的所需的最小操作数。

加入题单

算法标签: