Light oj 1202 - Bishops
来源:互联网 发布:触碰心灵的话 知乎 编辑:程序博客网 时间:2024/05/21 09:48
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
代码:
#include<cstdio>int main(){int n;scanf("%d",&n);long long a,b,c,d;for (int ca=1;ca<=n;ca++){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);if ((a+b)%2!=(c+d)%2){printf("Case %d: impossible\n",ca);continue;}if ((a+b==c+d)||(a-c==b-d))printf("Case %d: 1\n",ca);elseprintf("Case %d: 2\n",ca);}return 0;}
- Light oj 1202 - Bishops
- light oj 1202 - Bishops (规律)
- light oj 1202 - Bishops(规律推导)
- light oj
- light oj
- Light OJ
- Light OJ
- Light OJ 1000
- Light OJ 1001
- Light OJ 1008
- Light OJ 1022
- Light OJ 1015
- Light OJ 1042
- light oj 1128
- Light OJ 1055 BFS
- Light OJ Beginners Problems
- Light OJ Basic Geometry
- Light OJ Basic Math
- handler机制的原理
- LeetCode 121. Best Time to Buy and Sell Stock
- Java知识图谱收集整理
- AD10 PCB布线操作技巧
- Sybase修改字符集
- Light oj 1202 - Bishops
- 碰到的一个关于GregorianCalendar类的问题
- Ubuntu 14.04环境变量修改
- errno(3) 线程局部变量
- 【那些年遇到过的面试题】单例和静态类
- Android Studio异常:Fatal signal 11 (SIGSEGV) at 0x000000b4 (code=1)
- JUnit 4.8 源码解读2
- numberOfLeadingZeros(int i)源码探索
- kafka文档(3)---- 配置选项翻译