(SENIOR) Sir Ajay Somani and travelling
All submissions for this problem are available.
Sir Ajay Somani is passionate about traveling new places and experiencing new cultures. To plan this he creates a Cartesian map. He starts at origin (0,0).
Now he travels in the following manner:.
- Initially he is at origin position (0,0).
- In the beginning he goes 1 step to the East (i.e. In a single step, his x coordinate will increase by 1 unit.)
- then 2 steps to the North, (i.e. In a single step, his y coordinate will increase by 1 unit.)
- then 3 steps to the West, (i.e. In a single step, his x coordinate will decrease by 1 unit.)
- then 4 steps to the South, (i.e. In a single step, his y coordinate will decrease by 1 unit.)
- then 5 steps to the East,
As you can see after each travel he turns 90 degrees anticlockwise and it will then go one more step than before.
Now he wants to know whether he has visited the point (X, Y) or not.
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
For each test case, there is a single line containing two space-separated integers X and Y.
For each test case, output a single line containing "YES" (without qoutes) if he has visited the point (X,Y) and "NO" otherwise.
- 1 ≤ T ≤ 100000.
- -1000000000 ≤ X, Y ≤ 1000000000, i.e., -109 ≤ X, Y ≤ 109
Input: 3 3 3 3 5 0 0 Output: YES NO YES
The points (0, 0) and (3, 3) have been visited by him, while point (3, 5) has not been visited because point (3, 5) does not lie on his travel plan.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYP3|
Fetching successful submissions
If you are still having problems, see a sample solution here.