A15215 | Mirror Grid
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.

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.

输入格式
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.
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.
In the second test case, all rotations of the square are already the same, so we don't need any flips.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted