Problem
There is a grid of size , covered completely in railway tracks. Tom is riding in a train, currently in cell , and Jerry is tied up in a different cell , unable to move. The train has no breaks. It shall move exactly steps, and then its fuel will run out and it shall stop. In one step, the train must move to one of its neighboring cells, sharing a side. Tom can’t move without the train, as the grid is covered in tracks. Can Tom reach Jerry’s cell after exactly steps?
Note: Tom can go back to the same cell multiple times.
###Input
- The first line contains an integer , the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, five integers .
###Output For each testcase, output in a single line "YES" if Tom can reach Jerry's cell in exactly moves and "NO" if not.
You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
###Constraints
###Subtasks Subtask #1 (100 points): original constraints
Sample 1:
3
1 1 2 2 2
1 1 2 3 4
1 1 1 0 3
YES
NO
YES
Explanation:
Test Case : A possible sequence of moves is .
Test Case : There is a possible sequence in moves, but not in exactly moves.
Test Case : A possible sequence of moves is .
ANSWER
#include <iostream> | |
using namespace std; | |
int main() { | |
// your code goes here | |
int t; | |
cin>>t; | |
while(t--) { | |
int a,b,c,d,e; | |
cin>>a>>b>>c>>d>>e; | |
int max = abs(c-a) + abs(d-b); | |
if(max>e) { | |
cout<<"NO"<<endl; | |
} | |
else { | |
if((e-max)%2 == 0) { | |
cout<<"YES"<<endl; | |
} | |
else { | |
cout<<"NO"<<endl; | |
} | |
} | |
} | |
return 0; | |
} |