Codeforces #217 (Div. 2) A Rook, Bishop and King

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(r1, c1) to field (r2, c2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.

Input

The input contains four integers r1, c1, r2, c2 (1 ≤ r1, c1, r2, c2 ≤ 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.

Output

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 (r1, c1) to field (r2, c2). If a piece cannot make such a move, print a 0 instead of the corresponding number.

Sample test(s)
input
4 3 1 6
output
2 1 3
input
5 5 5 6
output
1 0 1


第二次做codeforces,坑得要死有木有大哭

尼玛就做出一题,最后还错了!!

题目的意思是对三种棋子有三种移动方法:

1、同行或同列随意移动步数

2、对角线上随意移动步数

3、任意方向移动一步

给出(r1,c1)    (r2,c2)

保证两坐标不同

输出三种移动方式下的最小步数

主要还是心态没有调整好,一心想着早点交导致错误和底下各种问题。

分析第一种情况:若行和列有一个相等的,则移动一次;两者均不同则移动两次。

分析第二种情况:可知一共有0、1、2三种可能,无法移动到则为0,在其主对角线上则为1,移动到对角线上某点后再以该位置为起始位置移动对角线为2;

结果为1对应的为abs(r1-r2)==abs(c1-c2);

结果为2对应的为abs(r1-r2)-abs(c1-c2)为2的倍数且不为0;

不符合两种情况的则对应0

分析第三种情况:若r1==r2,则移动abs(c1-c2);若c1==c2,则移动abs(r1-r2);若均不相等,则可分析得只需移动abs(c1-c2)和abs(r1-r2)中的较大者步即可!


在写博客的过程中才意识到最大的错误是没有看这个图!!!!!!!!!!发火

怒贴一记代码:

#include <stdio.h>
#include <stdlib.h>

int max(int a,int b)
{ return a>b?a:b;}

int main(void)
{
    int r1,c1,r2,c2;
    int a,b;
    while(scanf("%d%d%d%d",&r1,&c1,&r2,&c2)!=EOF)
    {
     int flag1=0,flag2=0,flag3=0;
     a=abs(r1-r2);
     b=abs(c1-c2);
     if(r1!=r2)
      flag1++;
     if(c1!=c2)
      flag1++;   
     if(abs(a-b)%2==0)
     {
      if(a==b)
       flag2=1;
      else
       flag2=2;
     }
     if(r1==r2)
      flag3=b;
     else if(c1==c2)
      flag3=a;
     else flag3=max(a,b);
     printf("%d %d %d\n",flag1,flag2,flag3);
    }
    return 0;
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值