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 pixels wide and pixels high. Consider the origin to be in the top-left corner of the screen, the -axis to go from the origin to the right, and the -axis to go from the origin to the bottom.
Rectangle () has a width of pixels, a height of pixels, initially its top-left corner has coordinates , and its initial movement direction is , where each of and is either or . At the end of each second, rectangle 's top-left corner coordinates instantly change by .
Whenever rectangle touches the left or the right border of the screen, the value of changes sign before the next second. Similarly, whenever rectangle touches the top or the bottom border of the screen, the value of changes sign before the next second. Whenever rectangle touches two borders of the screen at the same time (which can only happen at the corner of the screen), both and 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 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 be the number of integers such that the rectangles overlap during second (where second is before the rectangles start moving).
Find the limit of as 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 (). The description of the test cases follows.
The first line of each test case contains two integers and , denoting the width and the height of the screen ().
The next two lines describe the two rectangles. Each rectangle is described by six integers , , , , , , describing the -th rectangle and denoting its width, its height, the coordinates of its top-left corner, and its initial movement direction (; ; ; ; .
The sum of the values of across all test cases is guaranteed to not exceed .
输出格式
For each test case, print a non-negative integer and a positive integer , separated by a slash () without spaces, meaning that the limit of as is equal to . The fraction must be irreducible --- that is, the greatest common divisor of and must be equal to .
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 and . Thus, for example, .