21498_Knight'sTrip

2022-5-16 18:19| 发布者: Hocassian| 查看: 34| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505339416399-Problem List-采集的数据-后羿采集器.html

Pro.ID

21498

Title

Knight's Trip

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21498

AC

4

Submit

5

Ratio

80.00%

时间&空间限制

  • Time Limit: 200/100 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    In chess, each move of a knight consists of moving by two squares horizontally and one square vertically, or by one square horizontally and two squares vertically. A knight making one move from location (0,0) of an infinite chess board would end up at one of the following eight locations: (1,2), (-1,2), (1,-2), (-1,-2), (2,1), (-2,1), (2,-1), (-2,-1).

    Starting from location (0, 0), what is the minimum number of moves required for a knight to get to some other arbitrary location (x, y)?

    输入

    Each line of input contains two integers x and y, each with absolute value at most one billion. The integers designate a location (x, y) on the infinite chess board. The final line contains the word  END.

    输出

    Description

    In chess, each move of a knight consists of moving by two squares horizontally and one square vertically, or by one square horizontally and two squares vertically. A knight making one move from location (0,0) of an infinite chess board would end up at one of the following eight locations: (1,2), (-1,2), (1,-2), (-1,-2), (2,1), (-2,1), (2,-1), (-2,-1).

    Starting from location (0, 0), what is the minimum number of moves required for a knight to get to some other arbitrary location (x, y)?

    Input

    Each line of input contains two integers x and y, each with absolute value at most one billion. The integers designate a location (x, y) on the infinite chess board. The final line contains the word  END.

    Output

    For each location in the input, output a line containing one integer, the minimum number of moves required for a knight to move from (0,0) to (x, y).

    Sample Input

    1 2
    2 4
    END

    Sample Output

    1
    2

    Source

    样例输入

    1 2
    2 4
    END

    样例输出

    1
    2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部