博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lightoj1202——Bishops(找规律)
阅读量:2344 次
发布时间:2019-05-10

本文共 1571 字,大约阅读时间需要 5 分钟。

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

3
1 1 10 10
1 1 10 11
1 1 5 3
Output for Sample Input

Case 1: 1

Case 2: impossible
Case 3: 2

国际象棋上走象,求一只到另一只最少要多少步。

棋盘上画一下就知道只有三种情况:1步,2步或者达不到。
棋盘可以分为两个区域,一个是坐标全为奇数或者偶数的地方,其他事另一个
达不到的条件是两个象分别在不同的区域内
1步的条件是两者在同一条对角线上
2步的条件是两者不在同一条对角线上

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 2005#define Mod 10001using namespace std;int main(){ int t,cnt=1; scanf("%d",&t); while(t--) { long long r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; printf("Case %d: ",cnt++); if(abs(r1-r2)==abs(c1-c2)) printf("1\n"); else { if(r1%2==c1%2) { if(r2%2==c2%2) printf("2\n"); else printf("impossible\n"); } else { if(r2%2!=c2%2) printf("2\n"); else printf("impossible\n"); } } } return 0;}

转载地址:http://bpcvb.baihongyu.com/

你可能感兴趣的文章
多线程入门教程(四)线程间通信
查看>>
多线程入门教程(五)MFC的多线程
查看>>
多线程入门教程(六)综合实例
查看>>
C/C++ 多线程学习心得
查看>>
C/C++四种退出线程的方法
查看>>
多线程编程要点
查看>>
c++CreateEvent函数在多线程中使用及实例
查看>>
c++多线程同步(1)
查看>>
Windows 下 C/C++ 多线程编程入门参考范例
查看>>
浅析stack around the variable was corrupted
查看>>
RGB与YUV转换
查看>>
YUV转RGB的相关函数
查看>>
ES(Elasticsearch)排序与相关性
查看>>
ES(Elasticsearch)分片内部原理
查看>>
Java IO(概述)
查看>>
Java IO(文件、管道、字节和字符数组)
查看>>
Java IO(流、Reader And Writer、异常处理)
查看>>
Java IO(RandomAccessFile、File、PipedInputStream、PipedOutputStream)
查看>>
Java NIO(二) Channel
查看>>
Java NIO(三) Buffer
查看>>