CF370A.Rook, Bishop and King
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules:
- A rook moves any number of fields horizontally or vertically.
- A bishop moves any number of fields diagonally.
- A king moves one field in any direction — horizontally, vertically or diagonally.
The pieces move like that
Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (_r_1, _c_1) to field (_r_2, _c_2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.
小佩佳正在学习国际象棋。他已学会了王(king)、车(rook)和象(bishop)的走法。我们来回顾一下这些棋子的移动规则:国际象棋棋盘由 64 个方格组成,排列成 8×8 的表格。每个方格用一对整数 (r,c) 表示,分别代表行号和列号(在传统对局中,列通常用字母标记)。每个棋子恰好占据一个方格。一次“走子”即把某个棋子从一个方格移动到另一个方格,各棋子按如下规则移动:
- 车可沿水平或垂直方向移动任意格数;
- 象可沿对角线方向移动任意格数;
- 王可向任意方向(水平、垂直或对角线)移动一格。
棋子按此方式移动
佩佳正在思考如下问题:对于上述每种棋子,从起始方格 (r1,c1) 移动到目标方格 (r2,c2) 所需的最少步数是多少?假设棋盘上除该棋子外无其他任何棋子。请帮助他解决这一问题。
输入格式
The input contains four integers _r_1, _c_1, _r_2, _c_2 (1 ≤ _r_1, _c_1, _r_2, _c_2 ≤ 8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one.
You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.
输入包含四个整数 r1,c1,r2,c2(1 ≤ r1,c1,r2,c2 ≤ 8),表示起始格子与目标格子的坐标。起始格子与目标格子不重合。
你可以假设棋盘的行从上到下编号为 1 至 8,列从左到右编号为 1 至 8。
输出格式
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (_r_1, _c_1) to field (_r_2, _c_2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
输出三个用空格分隔的整数:车、象和王(按此顺序)从格子 (r1,c1) 移动到格子 (r2,c2) 所需的最少步数。如果某棋子无法完成该移动,则对应位置输出 0。
输入输出样例
输入#1
4 3 1 6
输出#1
2 1 3
输入#2
5 5 5 6
输出#2
1 0 1
输入解题思路,AI测评打分。不知道怎么写?