跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F0554. Problem D: Knight's Trip

  • ID: 560
  • 传统题
  • 1000ms
  • 128MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:待分级
  • 上传者:
  • 待分类
  • 整理状态
  • 难度待定
  • 难度
  • 共享题库
  • 高校与竞赛共享题
  • 英文题面
  • 题目来源
  • 题面语言

Problem D: Knight's Trip

题目描述

Problem D: Knight's Trip

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.

输出格式

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).

样例 1

输入

1 2
2 4
END

输出

1
2

题目来源:Waterloo ACM Programming Contest September 26, 2010;FPS 共享题包,题包内第 4 题。保留原作者与原赛事署名。