Legacy Screensaver

시간 제한3초메모리 제한2048 MB

요약
두 사각형이 화면 안에서 탄성 반사하며 움직일 때, 두 사각형이 겹치는 초의 비율의 극한을 기약분수로 구한다.
난이도

어려움10점 중 9점

유형
수학, 정수론, 조합론, 시뮬레이션
정답자
아직 제출이 없습니다

문제

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 w_iw\_i pixels, a height of h_ih\_i pixels, initially its top-left corner has coordinates (x_i,y_i)(x\_i, y\_i), and its initial movement direction is (δx_i,δy_i)(\delta x\_i, \delta y\_i), where each of δx_i\delta x\_i and δy_i\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 (δx_i,δy_i)(\delta x\_i, \delta y\_i).

Whenever rectangle ii touches the left or the right border of the screen, the value of δx_i\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 δy_i\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 δx_i\delta x\_i and δy_i\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,…,t−1\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 t→∞t \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 (1≤T≤10001 \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 (3≤W,H≤40003 \le W, H \le 4000).

The next two lines describe the two rectangles. Each rectangle is described by six integers w_iw\_i, h_ih\_i, x_ix\_i, y_iy\_i, δx_i\delta x\_i, δy_i\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 (1≤w_i≤W−21 \le w\_i \le W - 2; 1≤h_i≤H−21 \le h\_i \le H - 2; 0<x_i<W−w_i0 < x\_i < W - w\_i; 0<y_i<H−h_i0 < y\_i < H - h\_i; δx_i,δy_i∈−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 ('/') without spaces, meaning that the limit of f(t)t\frac{f(t)}{t} as t→∞t \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.

힌트

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.

예제1

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