欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1804A.Lame King
Lame King
You are given a checkerboard of size , i. e. it has rows and columns. The rows of this checkerboard are numbered from to from bottom to top. The columns of this checkerboard are numbered from to from left to right. The notation denotes the cell located in the -th row and the -th column.
There is a king piece at position and it wants to get to position as soon as possible. In this problem our king is lame. Each second, the king makes exactly one of the following five moves.
- Skip move. King's position remains unchanged.
- Go up. If the current position of the king is he goes to position .
- Go down. Position changes from to .
- Go right. Position changes from to .
- Go left. Position changes from to .
King is not allowed to make moves that put him outside of the board. The important consequence of the king being lame is that he is not allowed to make the same move during two consecutive seconds. For example, if the king goes right, the next second he can only skip, go up, down, or left.
What is the minimum number of seconds the lame king needs to reach position ?
Input
The first line of the input contains a single integer () — the number of test cases. Then follow lines containing one test case description each.
Each test case consists of two integers and () — the position of the cell that the king wants to reach. It is guaranteed that either or .
Output
Print integers. The -th of these integers should be equal to the minimum number of seconds the lame king needs to get to the position he wants to reach in the -th test case. The king always starts at position .
Note
One of the possible solutions for the first example is: go down, go right, go down, go right, go down, go left, go down.
One of the possible solutions for the second example is to alternate "go right" and "go up" moves times each.
One of the possible solutions for the third example is to alternate "go left" and "skip" moves starting with "go left". Thus, "go left" will be used times, and "skip" will be used times.
Samples
5
-4 1
4 4
0 -6
-5 -4
7 -8
7
8
11
9
15
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |