
1. Bob and Alice are standing at coordinates (0, 0) and (‘X’, ‘Y’), respectively, in the X-Y plane.
2. All the other ‘N’ friends are standing at some coordinates in the X-Y plane. The starting positions of all the ‘N’ friends are given as a 2 - Dimensional array of integers ‘positions’, where ‘position[i]’ denotes the starting position of the i-th friend.
3. In one move, Bob and his ‘N’ friends can independently choose to do one of the following two things:
1. Stay at their current position.
2. Move to any of the four neighboring positions, i.e., for any (x, y) move to north(x, y + 1), south(x, y - 1), east(x + 1, y), or west(x - 1, y).
All the coordinates are integral coordinates on the X-Y plane
There can be multiple friends with the same starting position(including Alice and Bob).
Bob and his ‘N’ friends move simultaneously.
Bob loses if he reaches any coordinate(including Alice’s position) at the same time as any of his ‘N’ friends.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains a single integer, ‘N’, where ‘N’ denotes the number of other friends of Alice and Bob.
The second line of each test case contains two space-separated integers, ‘X’ and ‘Y’, where (‘X’, ‘Y’) denote Alice’s position.
The next ‘N’ lines of each test case contain two space-separated integers, ‘position[i][0]’ and ‘position[i][1]’, where (‘position[i][0]’, ‘position[i][1]’) denotes the starting position of the i-th friend.
For each test case, print 1 if Bob can win the game, else print 0.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 5000
-10 ^ 7 <= X, Y <= 10 ^ 7
-10 ^ 7 <= position[i][0], position[i][1] <= 10 ^ 7
Time Limit: 1 sec
The idea here is to consider all those scenarios when Bob cannot win the game. There are two possible scenarios:
Let’s consider the 2nd scenario with a diagram,
Point A denotes the starting position of Bob, point D denotes the starting position of any of Bob’s ‘N’ friends, point C denotes the position of Alice, and point B denotes the position where Bob’s friend catches him before reaching Alice.
It is clear from the figure above that points B, D, and C form a triangle. Moreover, for his friend to catch him, AB must be equal to DB.
By the triangle inequality, DB + BC must be greater than or equal to DC, which is AB + BC must be greater than or equal to DC. Hence, AC must be greater than or equal to DC.
This means that for Bob’s friend to catch him before reaching Alice, the distance between Alice and Bob must be greater than or equal to the distance between Alice and his friend, which is the same as the 1st scenario as his friend can reach Alice before him. So we just need to check if any of Bob’s ‘N’ friends can reach Alice before him or not.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers