[Solved] 1202 – Bishops of LightOJ

IMG: Bishop Moves

Here is LightOJ Main Problem

There is an Infinite chessboard. Two bishops are there. (Bishop
means the chess piece that moves diagonally).

Now you are given the position of the two bishops. You have
to find the minimum chess moves to take one to another. With a chess move, a
bishop can be moved to a long distance (along the diagonal lines) with just one


Input starts with an integer T (≤ 10000),
denoting the number of test cases.

Each case contains four integers r1 c1
r2 c2
denoting the positions of the bishops. Each of
the integers will be positive and not greater than 109. You
can also assume that the positions will be distinct.


For each case, print the case number and the minimum moves
required to take one bishop to the other. Print ‘impossible’ if it’s not

Sample Input

Output for Sample Input


1 1 10 10

1 1 10 11

1 1 5 3

Case 1: 1

Case 2:

Case 3: 2


Full Source Code Using C Plus Plus

  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i,t;
  7.     long long int a,b,c,d;
  8.     long long int x,y;
  9.     cin>>t;
  10.     for(i=1;i<=t;i++)
  11.     {
  12.         cin>>a>>b>>c>>d;
  13.         x=abs(ca);
  14.         y=abs(db);
  15.         if(x==y) cout<<“Case “<<i<<“: 1”<<endl;
  16.         else if((xy)%2==0) cout<<“Case “<<i<<“: 2”<<endl;
  17.         else cout<<“Case “<<i<<“: impossible”<<endl;
  18.     }
  19. }

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *