QOJ.ac

QOJ

Time Limit: 3.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#10425. 经典屏保

Statistics

在一个非常古老的操作系统上,屏幕保护程序由两个在屏幕上飞行的矩形组成。屏幕的宽度为 $W$ 像素,高度为 $H$ 像素。考虑屏幕左上角为原点,x 轴从原点向右延伸,y 轴从原点向下延伸。

矩形 $i$ ($i = 1, 2$) 的宽度为 $w_i$ 像素,高度为 $h_i$ 像素,其左上角初始坐标为 $(x_i, y_i)$,初始运动方向为 $(\delta x_i, \delta y_i)$,其中 $\delta x_i$ 和 $\delta y_i$ 均为 $-1$ 或 $1$。在每一秒结束时,矩形 $i$ 的左上角坐标会瞬间改变 $(\delta x_i, \delta y_i)$。

每当矩形 $i$ 碰到屏幕的左边界或右边界时,$\delta x_i$ 的值会在下一秒之前改变符号。同样,每当矩形 $i$ 碰到屏幕的顶边界或底边界时,$\delta y_i$ 的值会在下一秒之前改变符号。每当矩形 $i$ 同时碰到屏幕的两个边界时(这种情况只可能发生在屏幕角落),$\delta x_i$ 和 $\delta y_i$ 都会改变符号。

由于上述规则,两个矩形始终完全保持在屏幕内。非正式地说,矩形与屏幕边界的碰撞是完全弹性的。但请注意,矩形的运动仍然是离散的:每个矩形在每一秒结束时瞬间移动 1 个像素。

你很好奇这两个矩形重叠的频率。如果两个矩形的交集面积为正,则认为它们重叠。

令 $f(t)$ 为满足矩形在第 $\tau$ 秒重叠的整数 $\tau = 0, 1, \dots, t - 1$ 的个数(其中第 0 秒是矩形开始移动之前)。

求当 $t \to \infty$ 时 $\frac{f(t)}{t}$ 的极限,并以不可约分数形式输出。可以证明该极限是一个有理数。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $T$ ($1 \le T \le 1000$)。接下来是各测试用例的描述。

每个测试用例的第一行包含两个整数 $W$ 和 $H$,表示屏幕的宽度和高度 ($3 \le W, H \le 4000$)。

接下来的两行描述两个矩形。每个矩形由六个整数 $w_i, h_i, x_i, y_i, \delta x_i, \delta y_i$ 描述,分别表示第 $i$ 个矩形的宽度、高度、左上角坐标及其初始运动方向 ($1 \le w_i \le W - 2; 1 \le h_i \le H - 2; 0 < x_i < W - w_i; 0 < y_i < H - h_i; \delta x_i, \delta y_i \in \{-1, 1\}$)。

保证所有测试用例中 $W + H$ 的总和不超过 8000。

输出格式

对于每个测试用例,输出一个非负整数 $p$ 和一个正整数 $q$,中间用斜杠('/')分隔,不含空格,表示当 $t \to \infty$ 时 $\frac{f(t)}{t}$ 的极限等于 $\frac{p}{q}$。该分数必须是不可约的,即 $p$ 和 $q$ 的最大公约数必须为 1。

样例

输入格式 1

2
3 3
1 1 1 1 1 1
1 1 1 1 1 -1
5 4
2 2 1 1 -1 -1
2 1 2 2 1 -1

输出格式 1

1/2
1/3

说明

对于第二个测试用例,矩形在最初几秒的状态如下图所示。矩形在 $\tau = 0$ 和 $\tau = 6$ 时重叠。因此,例如 $f(8) = 2$。

$\tau = 0$ 到 $\tau = 7$ 时矩形的状态

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.