欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1845B.Come Together
Come Together
Bob and Carol hanged out with Alice the whole day, but now it's time to go home. Alice, Bob and Carol live on an infinite 2D grid in cells , , and respectively. Right now, all of them are in cell .
If Bob (or Carol) is in some cell, he (she) can move to one of the neighboring cells. Two cells are called neighboring if they share a side. For example, the cell has four neighboring cells: , , and .
Bob wants to return to the cell , Carol — to the cell . Both of them want to go along the shortest path, i. e. along the path that consists of the minimum possible number of cells. But they would like to walk together as well.
What is the maximum possible number of cells that Bob and Carol can walk together if each of them walks home using one of the shortest paths?
Input
The first line contains the single integer () — the number of test cases.
The first line of each test case contains two integers and () — the position of cell , where both Bob and Carol are right now.
The second line contains two integers and () — the position of cell (Bob's house).
The third line contains two integers and () — the position of cell (Carol's house).
Additional constraint on the input: the cells , , and are pairwise distinct in each test case.
Output
For each test case, print the single integer — the maximum number of cells Bob and Carol can walk together if each of them goes home along one of the shortest paths.
Note
In all pictures, red color denotes cells belonging only to Bob's path, light blue color — cells belonging only to Carol's path, and dark blue color — cells belonging to both paths.
One of the optimal routes for the first test case is shown below:
Bob's route contains cells, Carol's route — cells, and they will visit cells together.
The optimal answer for the second test case is shown below:
Bob's route contains cells, Carol's route — cells, and they will visit only cell together.
One of the optimal answers for the third test case is shown below:
Bob's route contains cells, Carol's route — cells, and they will visit cells together.
Samples
3
3 1
1 3
6 4
5 2
2 2
7 2
1 1
4 3
5 5
3
1
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |