May 27, 2016
[Solved] 1202 – Bishops of LightOJ
![[Solved] 1202 – Bishops of LightOJ](/blog/solved-1202-bishops-lightoj/featured.jpg)

Main Problem
There is an infinite chessboard. Two bishops are there (a bishop is the chess piece that moves diagonally).
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 a long distance (along the diagonal lines) with just one move.
Input
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 10^9. You can also assume that the positions will be distinct.
Output
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 possible.
| Sample Input | Output for Sample Input |
|---|---|
| 3 | Case 1: 1 |
| 1 1 10 10 | Case 2: impossible |
| 1 1 10 11 | Case 3: 2 |
| 1 1 5 3 |
Solution
Full Source Code (C++)
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,t;
long long int a,b,c,d;
long long int x,y;
cin>>t;
for(i=1;i<=t;i++)
{
cin>>a>>b>>c>>d;
x=abs(c-a);
y=abs(d-b);
if(x==y) cout<<"Case "<<i<<": 1"<<endl;
else if((x-y)%2==0) cout<<"Case "<<i<<": 2"<<endl;
else cout<<"Case "<<i<<": impossible"<<endl;
}
}
- 1202 - Bishops
- lightoj
- online judge
- solve