light oj 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

 

规律:坐标之和为全奇数或全偶数时,可以走到,否则不能走到
可以走到分:
(1)横纵坐标之差的绝对值相等,只需1步;
(2)其他需要两步
代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    int t,k=1,x1,y1,x2,y2;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        if((x1+y1)%2!=(x2+y2)%2)
            printf("Case %d: impossible\n",k++);
        else
        {
            if(abs(x1-x2)==abs(y1-y2))
                printf("Case %d: 1\n",k++);
            else
                printf("Case %d: 2\n",k++);
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值