QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21246. 二進位數獨

Statistics

Farmer John 的牛喜歡玩熱門遊戲「數獨」的一種有趣變體。和普通數獨一樣,牠們的版本使用一個由 $3 \times 3$ 子網格組成的 $9 \times 9$ 網格。不過,牛隻的版本只使用二進位數字:

000 000 000
001 000 100
000 000 000

000 110 000
000 111 000
000 000 000

000 000 000
000 000 000
000 000 000

二進位數獨的目標是翻轉盡可能少的位元,使九列中的每一列、九行中的每一行以及九個 $3 \times 3$ 子網格中的每一個都具有偶同位性(即包含偶數個 $1$)。對於上面的例子,翻轉 3 個位元就可以得到一個合法解:

000 000 000
001 000 100
001 000 100

000 110 000
000 110 000
000 000 000

000 000 000
000 000 000
000 000 000

給定二進位數獨棋盤的初始狀態,請幫助牛隻確定解出它所需的最少翻轉次數。

輸入格式

  • 第 $1..9$ 行:每行包含一個 9 位元的二進位字串,對應初始棋盤的一列。

輸出格式

  • 第 1 行:使每列、每行和每個子網格都具有偶同位性所需的最少翻轉次數。

範例

輸入格式 1

000000000
001000100
000000000
000110000
000111000
000000000
000000000
000000000
000000000

輸出格式 1

3

說明

範例輸入中的數獨棋盤與上面題目敘述中的相同。

翻轉三次就足以解出這道謎題。

題目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.