luogu#P12103. [NERC2024] Legacy Screensaver

[NERC2024] Legacy Screensaver

题目描述

On a very old operating system, a screensaver consists of two rectangles flying around the screen. The screen is WW pixels wide and HH pixels high. Consider the origin to be in the top-left corner of the screen, the xx-axis to go from the origin to the right, and the yy-axis to go from the origin to the bottom.

Rectangle ii (i=1,2i = 1, 2) has a width of wiw_i pixels, a height of hih_i pixels, initially its top-left corner has coordinates (xi,yi)(x_i, y_i), and its initial movement direction is (δxi,δyi)(\delta x_i, \delta y_i), where each of δxi\delta x_i and δyi\delta y_i is either 1-1 or 11. At the end of each second, rectangle ii's top-left corner coordinates instantly change by (δxi,δyi)(\delta x_i, \delta y_i).

Whenever rectangle ii touches the left or the right border of the screen, the value of δxi\delta x_i changes sign before the next second. Similarly, whenever rectangle ii touches the top or the bottom border of the screen, the value of δyi\delta y_i changes sign before the next second. Whenever rectangle ii touches two borders of the screen at the same time (which can only happen at the corner of the screen), both δxi\delta x_i and δyi\delta y_i change sign.

As a result of the above, both rectangles stay fully within the screen at all times. Informally, collisions of the rectangles with the screen borders are perfectly elastic. Note, however, that rectangle movement is still discrete: each rectangle moves instantly by 11 pixel in both directions at the end of each second.

You are curious how often these two rectangles overlap. The rectangles are considered to be overlapping if their intersection has a positive area.

Let f(t)f(t) be the number of integers τ=0,1,,t1\tau = 0, 1, \ldots, t - 1 such that the rectangles overlap during second τ\tau (where second 00 is before the rectangles start moving).

Find the limit of f(t)t\frac{f(t)}{t} as tt \rightarrow \infty as an irreducible fraction. It can be shown that this limit is a rational number.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases TT (1T10001 \le T \le 1000). The description of the test cases follows.

The first line of each test case contains two integers WW and HH, denoting the width and the height of the screen (3W,H40003 \le W, H \le 4000).

The next two lines describe the two rectangles. Each rectangle is described by six integers wiw_i, hih_i, xix_i, yiy_i, δxi\delta x_i, δyi\delta y_i, describing the ii-th rectangle and denoting its width, its height, the coordinates of its top-left corner, and its initial movement direction (1wiW21 \le w_i \le W - 2; 1hiH21 \le h_i \le H - 2; 0<xi<Wwi0 < x_i < W - w_i; 0<yi<Hhi0 < y_i < H - h_i; δxi,δyi{1,1})\delta x_i, \delta y_i \in \{-1, 1\}).

The sum of the values of W+HW + H across all test cases is guaranteed to not exceed 80008000.

输出格式

For each test case, print a non-negative integer pp and a positive integer qq, separated by a slash (/\tt{/}) without spaces, meaning that the limit of f(t)t\frac{f(t)}{t} as tt \rightarrow \infty is equal to pq\frac{p}{q}. The fraction must be irreducible --- that is, the greatest common divisor of pp and qq must be equal to 11.

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/2
1/3

提示

For the second test case, the state of rectangles during the first few seconds is shown in the following pictures. The rectangles overlap during seconds τ=0\tau = 0 and τ=6\tau = 6. Thus, for example, f(8)=2f(8) = 2.