![]() So, in any case, a block of the same color that needs to be reached via a common block will require only 2 moves. In other words, there is always at least 1 block and at best 2 blocks in common between the destination block and initial block. But in case of switching to a block of the same color of its current position that is not directly diagonally connected, observing the chessboard we can see that we need to move to another block that is already diagonally connected to the destination block we want. We already know diagonal blocks can be reached in 1 move. Now to determine whether it can be reached at all or impossible, we need to know if the block we are trying reach is of the same color of the Bishop's initial block or not. If the condition is not met, either the position can not be taken in 1 move or it is impossible. This is how we know that the destination block can be reached diagonally directly in 1 move. ![]() If a Bishop makes a move from its initial block to any diagonal direction, the difference of new x-coordinate and y-coordinate from their initial block is equal, |c1-c2| = |r1-r2|. Outputįor each case, print the case number and the minimum moves required to take one bishop to the other. You can also assume that the positions will be distinct. Each of the integers will be positive and not greater than 10 9. Input starts with an integer T (≤ 10000), denoting the number of test cases.Įach case contains four integers r1 c1 r2 c2 denoting the positions of the bishops. With a chess move, a bishop can be moved to a long distance (along the diagonal lines) with just one move. You have to find the minimum chess moves to take one to another. Now you are given the position of the two bishops. (Bishop means the chess piece that moves diagonally).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |