B. Line Segments
Problem Statement
You are given two points and on a Euclidean plane.
You start at the starting point and will perform operations. In the -th operation, you must choose any point such that the Euclidean distance* between your current position and the point is exactly , and then move to that point.
Determine whether it is possible to reach the terminal point after performing all operations.
*The Euclidean distance between and is .
Input
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 a single integer — the length of the sequence .
The second line of each test case contains four integers — the coordinates of the starting point and terminal point.
The third line of each test case contains integers — the distance to move in each operation.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output “Yes” if it is possible to reach the terminal point after all operations; otherwise, output “No”.
You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.
Solution
For each move, we can choose any point on the circle with radius centered at the current position. The distance to the target point will then have a range of , where is the distance from the current position to . We rewrite this range as .
- We begin with the initial range , where , and is the distance from to .
- For each move , we update the range as follows:
- If or , then the new minimum distance can be 0, so .
- Update and for the next iteration.
- After all moves, if is within the final range , then it’s possible to reach the target point.