lightOJ 1202 Bishops

1202 - Bishops
Time Limit: 1 second(s) Memory Limit: 32 MB

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 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 109. 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

1 1 10 10

1 1 10 11

1 1 5 3

Case 1: 1

Case 2: impossible

Case 3: 2

 


Special Thanks: Jane Alam Jan (Description, Solution, Dataset)

//简单规律题

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
    int r1,r2,c1,c2;
    int T,t=1;
    scanf("%d",&T);
    while(T--)
    {
       scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
       printf("Case %d: ",t++);
       if(r1==r2&&c1==c2)
       {
          printf("0\n"); continue;
       }

       if((r1-c1+r2-c2)%2)
         printf("impossible\n");
      else
       {
           if(r1-c1==r2-c2||r1+c1==r2+c2)
             printf("1\n");
           else
             printf("2\n");
       }

    }
    return 0;
}

你可能感兴趣的:(PS)