Mobile Gaming
Time limit1sMemory limit256 MB
Two rectangles move at constant speed from time 0 to 1; report the first moment they touch or overlap, or report no collision.
Problem
Online gaming on mobile phones has become popular, so you are building a cops and robbers game. Some players control the cops, and the others control the robbers. A cop wants to catch a robber, and a robber tries to escape.
During development you ran into a problem. The phones update slowly, and you sometimes get a player position only once per second. Scoring depends on the moment a cop caught a robber, so you have to compute that moment exactly.
Cops and robbers are rectangles in the game world, and a cop has caught a robber when their rectangles overlap. You are given the size of each rectangle and its position at time 0 and at time 1. Decide whether the two rectangles overlap at some moment between time 0 and time 1, and if they do, find the first such moment.
Input
The first line contains the number of test cases . Each test case consists of two lines with six integers each.
The first line contains , , , , , . and are the width and the height of the cop rectangle. is its upper left corner at time 0, and is its upper left corner at time 1.
The second line contains the same six values for the robber: , , , , , .
- Every value in the input is an integer.
- In the coordinate system grows from left to right and grows from top to bottom.
- A collision happens when the two rectangles overlap, and also when only their sides or corners touch.
- The cop and the robber each move along a straight line at constant speed from the position at time 0 to the position at time 1.
Output
For each test case, print the first moment at which a collision happens, one moment per line. The value lies between 0 and 1, inclusive.
Round at the seventh digit after the decimal point and always print exactly six digits, so write 0.000000 or 1.000000 with the trailing zeros. A value that falls exactly halfway rounds up.
If there is no collision, print No Collision instead.