QOJ.ac

QOJ

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

#13138. 冰上机器人

Statistics

受哈尔滨冰雕的启发,来自北极机器人与自动化大学的编程团队决定在比赛结束后回到家乡举办他们自己的冰雪节。他们计划在冬天湖面结冰时从附近的湖中采集冰块。为了更方便地监测冰层厚度,他们将在湖面上铺设一个矩形网格,并让一个轻型机器人从一个方格移动到另一个方格,以测量网格中每个方格的冰层厚度。网格中有三个位置被指定为“签到”点,机器人需要在其巡检行程的四分之一、二分之一和四分之三处从这些点发送进度报告。为了避免对冰面造成不必要的磨损,机器人必须从左下角(坐标记为 $(0,0)$)开始其巡检行程,访问每一个其他网格位置恰好一次,并以行 $0$、列 $1$ 作为行程的终点。此外,如果机器人有多种巡检路径可供选择,则每天应使用不同的路径。机器人每一步只能向北、南、东、西四个罗盘方向之一移动一个方格。

你需要设计一个程序,计算对于给定的网格大小和三个签到点的序列,有多少种可能的巡检路径。例如,假设湖面被划分为 $3 \times 6$ 的网格,且签到点按访问顺序依次为 $(2,1)$、$(2,4)$ 和 $(0,4)$。那么机器人必须从 $(0,0)$ 出发,在访问完所有 $18$ 个方格后在 $(0,1)$ 结束。它必须在第 $4$ 步($= \lfloor 18/4 \rfloor$)到达位置 $(2,1)$,在第 $9$ 步($= \lfloor 18/2 \rfloor$)到达位置 $(2,4)$,并在第 $13$ 步($= \lfloor 3 \times 18/4 \rfloor$)到达位置 $(0,4)$。实现这一目标的路径共有两种(见 Figure 8)。注意,当网格大小不能被 $4$ 整除时,使用截断除法来确定三个签到时间。

Figure 8

注意,某些配置可能根本不允许任何有效的巡检路径。例如,在一个 $4 \times 3$ 的网格中,签到序列为 $(2,0)$、$(3,2)$ 和 $(0,2)$ 时,不存在从 $(0,0)$ 开始并以 $(0,1)$ 结束的网格巡检路径。

输入格式

输入包含多个测试用例。每个测试用例以一行包含两个整数 $m$ 和 $n$ 开始,其中 $2 \le m,n \le 8$,分别指定网格的行数和列数。接下来一行包含六个整数值 $r_1, c_1, r_2, c_2$ 和 $r_3, c_3$,其中对于 $i = 1, 2, 3$,有 $0 \le r_i < m$ 且 $0 \le c_i < n$。

最后一个测试用例之后是一行包含两个零的输入。

输出格式

显示用例编号(从 $1$ 开始),后跟从行 $0$、列 $0$ 开始,以行 $0$、列 $1$ 结束,并在时间 $\lfloor i \times m \times n / 4 \rfloor$ 访问行 $r_i$、列 $c_i$(对于 $i = 1, 2, 3$)的可能巡检路径数量。请遵循样例输出的格式。

样例

输入格式 1

3 6 
2 1 2 4 0 4 
4 3 
2 0 3 2 0 2 
0 0

输出格式 1

Case 1: 2
Case 2: 0

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.