CF1703E.Mirror Grid

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a square grid with nn rows and nn columns. Each cell contains either 00 or 11.

In an operation, you can select a cell of the grid and flip it (from 0→10 \to 1 or 1→01 \to 0). Find the minimum number of operations you need to obtain a square that remains the same when rotated 0∘0^{\circ}, 90∘90^{\circ}, 180∘180^{\circ} and 270∘270^{\circ}.

The picture below shows an example of all rotations of a grid.

给你一个 nn 行 nn 列的方阵网格,每个格子中包含数字 00 或 11。

每次操作中,你可以选择网格中的一个格子并将其翻转(即 0→10 \to 1 或 1→01 \to 0)。求使该方阵在旋转 0∘0^{\circ}、90∘90^{\circ}、180∘180^{\circ} 和 270∘270^{\circ} 后均保持不变所需的最少操作次数。

下图展示了一个网格的所有旋转示例:

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1001 \leq n \leq 100) — the size of the grid.

Then nn lines follow, each with nn characters ai,ja_{i,j} (0≤ai,j≤10 \leq a_{i,j} \leq 1) — the number written in each cell.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 网格的大小。

接下来是 nn 行,每行包含 nn 个字符 ai,ja_{i,j}(0≤ai,j≤10 \leq a_{i,j} \leq 1)—— 每个单元格中所写的数字。

输出格式

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

对于每个测试用例,输出一个整数——使正方形在旋转 0∘0^{\circ}、90∘90^{\circ}、180∘180^{\circ} 和 270∘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 010111010\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.

在第一个测试用例中,我们可以执行一次操作,使网格变为 010111010\begin{matrix}0 & 1 & 0\\ 1 & 1 & \color{red}{1}\\ 0 & 1 & 0\end{matrix}。此时,该正方形的所有旋转结果均相同。

在第二个测试用例中,该正方形的所有旋转结果已经相同,因此无需任何翻转操作。

输入解题思路,AI测评打分。不知道怎么写?

首页