GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Tuesday, 12 July 2022

[Solution] Mirror Grid Codeforces Solution | Solution Codeforces



Mirror Grid solution codeforces – You are given a square grid with 𝑛n rows and 𝑛n columns. Each cell contains either 00 or 11.
[Solution] Mirror Grid solution codeforces
In an operation, you can select a cell of the grid and flip it (from 0→10→1 or 1→01→0). Find the minimum number of operations you need to obtain a square that remains the same when rotated 0∘0∘, 90∘90∘, 180∘180∘ and 270∘270∘.

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

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

Mirror Grid solution codeforces
Input
The first line contains a single integer 𝑡t (1≤𝑡≤1001≤t≤100) — the number of test cases.

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

Then 𝑛n lines follow, each with 𝑛n characters 𝑎𝑖,𝑗ai,j (0≤𝑎𝑖,𝑗≤10≤ai,j≤1) — the number written in each cell.


[Solution] Mirror Grid solution codeforces
For each test case output a single integer  — the minimum number of operations needed to make the square look the same rotated 0∘0∘, 90∘90∘, 180∘180∘ and 270∘270∘.

Example
input
Copy
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
[Solution] Mirror Grid solution codeforces
output
Copy
1
0
9
7
6
Note
In the first test case, we can perform one operations to make the grid 010111010010111010. 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.

No comments:

Post a Comment