CC1 - Editorial

PROBLEM LINK

http://www.codechef.com/CDCRNT14/problems/CC1

DIFFICULTY

Cake walk

PROBLEM

Chris brown has to get to Rihanna with in less moves, he can move diagonally, in one move he can take as many steps as he want unless he takes a turn. If he takes a turn it is another move.

EXPLANATION

Think the grid is like a chess board, and Chris brown like a bishop, now if you color the grid with white and black in chess board,
Case 1:
If both the co-ordinates are same answer is 0
Case 2:
If Chris is in white and Rihanna in black or vice-versa answer is -1
Case 3:
If both are in same color and the absolute difference of x-coordinates and y-coordinates is equal answer is 1
Case 4:
If both are in same color and the absolute difference of x-coordinates and y-coordinates is not equal answer is 2

2 Likes