#P15553. [CCPC 2025 哈尔滨站] 液压机
[CCPC 2025 哈尔滨站] 液压机
Problem Description
In a 2D testing field, four infinitely long straight lines are used as movable “walls”: the top and bottom are horizontal lines, and the left and right are vertical lines. After placing a small ball whose size can be ignored, the ball moves in uniform straight-line motion. Whenever it touches one of a pair of parallel walls, it bounces along the normal direction ( only the sign of the velocity component in that direction changes ), while the velocity component in the other direction remains unchanged. The two horizontal lines move toward each other, and the two vertical lines move toward each other as well. Eventually, at some moment, the walls will close up and trap the ball.
Given the ball’s initial position and velocity, and the initial positions and velocities of the four lines, you need to treat the time when the two horizontal lines meet as the ending time, and output the ball’s coordinates at that time.
The ball’s initial position is , and its initial velocity is .
Initially, the lower and upper horizontal lines are at and , respectively. After time , they move to and .
Initially, the left and right vertical lines are at and , respectively. After time , they move to and .
It is guaranteed that at the beginning the ball is inside the rectangle formed by the four lines, i.e. and .
:::align{center}

Initial state of the sample :::
We guarantee that in every collision, the ball hits the wall first. That is, the speed of the ball in the vertical direction is always greater than the moving speeds of the two horizontal lines: .
To ensure that the top and bottom lines will definitely meet, it is guaranteed that their speeds are not both at the same time.
The collision rules are as follows:
- When the ball does not touch any line, it moves in uniform straight-line motion.
- When it touches a horizontal line, only the vertical velocity is negated (change to ), while the horizontal velocity remains unchanged.
- When it touches a vertical line, only the horizontal velocity is negated (change to ), while the vertical velocity remains unchanged.
- The bounce decision is independent of the translation speed of the line, and is handled only by “negating” the corresponding velocity component.
Input Format
The problem contains multiple groups of testdata. The first line contains an integer , representing the number of test cases.
Then for each test case:
The first line contains four integers (, 、), representing the ball’s initial coordinates and initial velocity.
The second line contains four integers (, , ), representing the initial positions and moving speeds of the horizontal lines.
The third line contains four integers (, ), representing the initial positions and moving speeds of the vertical lines.
Output Format
For each test case, output one line with two floating-point numbers separated by a space, representing the ball’s coordinates at the ending time.
If the absolute error or relative error between your output and the standard answer does not exceed , then your answer will be judged correct.
In other words, suppose your answer is and the standard answer is . If:
then your answer will be considered correct.
1
3 4 2 5
0 10 3 2
0 10 1 0
7.000000000000 6.000000000000
2
631043 768016 20 20
1 1000000 1 0
631040 631050 1 0
631044 768016 20 20
1 1000000 1 0
631041 631051 1 0
-0.456742460183 1000000.000000000000
0.543257539817 1000000.000000000000
Hint
Translated by ChatGPT 5