QOJ.ac

QOJ

時間限制: 60.0 s 記憶體限制: 256 MB 總分: 100

#17520. 尴尬的灯光

统计

你在一栋办公楼里担任夜间值班保安。你的任务是在大楼里的所有上班族都离开办公室后,检查大楼里的所有灯是否都已关闭。如果还有亮着的灯,你必须把它们关掉。由于大楼照明系统的奇异行为(如下所述),这项任务并不像听起来那么简单。尽管一位电机工程师仔细检查了照明系统,但他无法确定这种行为的原因。因此,目前你别无选择,只能继续依赖这个系统。

大楼的每一层都由一个正方形房间组成的网格构成。每个房间都配备了一盏灯和一个拨动开关。拨动开关有两个位置,但它们并不代表固定的开/关(ON/OFF)状态。当某个房间的拨动开关位置被切换到另一个位置时,除了该房间本身之外,与该房间的曼哈顿距离恰好为给定值的所有房间的灯的开/关状态也会被反转。网格中位于 $(x_1, y_1)$ 的房间与位于 $(x_2, y_2)$ 的房间之间的曼哈顿距离由 $|x_1 - x_2| + |y_1 - y_2|$ 给出。例如,如果在一个 $4 \times 4$ 的房间网格中,切换位于 $(2, 2)$ 的房间的开关位置,且给定的曼哈顿距离为 $2$,那么位于 $(1, 1)$、$(1, 3)$、$(2, 4)$、$(3, 1)$、$(3, 3)$ 和 $(4, 2)$ 以及 $(2, 2)$ 的房间的灯的开/关状态都会被反转,如图 D.1 所示,其中黑色和白色方块分别代表灯的开/关状态。

图 D.1:照明系统行为的一个示例

你的任务是编写一个程序,判断是否可以将某一层的所有灯都关闭。

输入格式

输入由一系列数据集组成。每个数据集的格式如下:

$m$ $n$ $d$ $S_{11}$ $S_{12}$ $S_{13}$ ... $S_{1m}$ $S_{21}$ $S_{22}$ $S_{23}$ ... $S_{2m}$ ... $S_{n1}$ $S_{n2}$ $S_{n3}$ ... $S_{nm}$

数据集的第一行包含三个整数。$m$ 和 $n$($1 \le m \le 25$,$1 \le n \le 25$)分别是网格的列数和行数。$d$($1 \le d \le m + n$)表示曼哈顿距离。接下来的 $n$ 行,每行包含 $m$ 个整数,表示初始的开/关状态。每个 $S_{ij}$($1 \le i \le n$,$1 \le j \le m$)表示位于 $(i, j)$ 的房间的灯的初始开/关状态:“0”表示关,“1”表示开。

输入结束由包含三个零的一行指示。

输出格式

对于每个数据集,如果所有灯都可以被关闭,则输出 “1”;否则输出 “0”。对于每个输入数据集,结果应单独输出在一行中。

样例

样例输入 1

1 1 1
1
2 2 1
1 1
1 1
3 2 1
1 0 1
0 1 0
3 3 1
1 0 1
0 1 0
1 0 1
4 4 2
1 1 0 1
0 0 0 1
1 0 1 1
1 0 0 0
5 5 1
1 1 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
5 5 2
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
11 11 3
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
11 11 3
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
13 13 7
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0

样例输出 1

1
1
0
1
0
0
1
1
0
1

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.