QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 15

#5784. 乒乓球

Statistics

一个大房间里布满了网格状排列的捕鼠夹。每个捕鼠夹上都放置了两个乒乓球,摆放得非常巧妙,一旦捕鼠夹触发,球就会被弹射出去,落在其他捕鼠夹上并触发它们。房间的墙壁具有粘性,因此任何撞击到墙壁的球都会被吸收。

每个被触发的捕鼠夹都会以相同的方式弹射出两个乒乓球:它们的运动由相对于触发捕鼠夹的 $X$ 和 $Y$ 位移决定。你决定向房间内发射一个乒乓球。它会击中一个捕鼠夹,将其触发,并弹射出两个球。这两个球随后会触发另外两个捕鼠夹,接着四个球飞出……当尘埃落定时,许多捕鼠夹已被触发,但仍有一些未被任何飞行的球击中。

你需要计算总共有多少个捕鼠夹被触发。

作为一个例子(见第一个样例测试用例),下图展示了一个宽为 5、高为 3 的房间。每个房间中乒乓球的两个方向分别为 $(-1, 0)$ 和 $(-1, -1)$。你发射的第一个球击中了位于 $(4, 2)$ 的捕鼠夹。最终,共有 12 个捕鼠夹被触发。

输入的第一行包含测试用例的数量 $C$。接下来是 $C$ 个测试用例。每个用例包含四行。第一行是捕鼠夹网格的大小(等于房间的大小),由宽度 $W$ 和高度 $H$ 给定。接下来的两行给出了两个乒乓球的目标位置,以 $X$ 和 $Y$ 位移表示。例如,如果这两行分别是 0 11 1,那么触发一个捕鼠夹会发射两个球;一个会击中触发捕鼠夹正上方的捕鼠夹,另一个会击中触发捕鼠夹右上方对角线的捕鼠夹。最后一行包含两个整数,分别指定了被初始乒乓球触发的捕鼠夹的列和行(其中 $0\ 0$ 为左下角的捕鼠夹)。

对于每个测试用例,输出一行 "Case #$A$: $B$",其中 $A$ 是从 1 开始的用例编号,$B$ 是被触发的捕鼠夹总数(包括第一个被触发的)。

样例

输入格式 1

3
5 3
-1 0
-1 -1
4 2
50 50
0 1
1 1
10 10
6 2
2 0
3 0
0 0

输出格式 1

Case #1: 12
Case #2: 820
Case #3: 5

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.