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 A, B, and C respectively. Right now, all of them are in cell A.
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 (3,5)(3,5) has four neighboring cells: (2,5)(2,5), (4,5)(4,5), (3,6)(3,6) and (3,4)(3,4).
Bob wants to return to the cell B, Carol — to the cell C. 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 t (1≤t≤1041≤≤104) — the number of test cases.
The first line of each test case contains two integers xA and yA (1≤xA,yA≤1081≤,≤108) — the position of cell A, where both Bob and Carol are right now.
The second line contains two integers xB and yB (1≤xB,yB≤1081≤,≤108) — the position of cell B (Bob's house).
The third line contains two integers xC and yC (1≤xC,yC≤1081≤,≤108) — the position of cell C (Carol's house).
Additional constraint on the input: the cells A, B, and C 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.
Example
input
Copy
3
3 1
1 3
6 4
5 2
2 2
7 2
1 1
4 3
5 5
output
Copy
3
1
6
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 55 cells, Carol's route — 77 cells, and they will visit 33 cells together.
The optimal answer for the second test case is shown below:
Bob's route contains 44 cells, Carol's route — 33 cells, and they will visit only 11 cell together.
One of the optimal answers for the third test case is shown below:
Bob's route contains 66 cells, Carol's route — 99 cells, and they will visit 66 cells together.
//Come Together
//将x,y分开看
//如果a在b和c的中间的话,那么他俩肯定要分开走的,所以默认是1#include <bits/stdc++.h>
#define int long long
usingnamespace std;
constint N=1e6+10,mod=1e9+7;
string s;
int n,t,a[N],f[N],res,num,ans,m;
bool vis[N];
signed main()
{
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>t;
while(t--){
int xa,ya,xb,yb,xc,yc;
cin>>xa>>ya>>xb>>yb>>xc>>yc;
int x1=xa-xb,x2=xa-xc,y1=ya-yb,y2=ya-yc,res=1;
if(x1<0&&x2<0||x1>0&&x2>0) res+=min(abs(x1),abs(x2));//都在左侧或者都在右侧if(y1<0&&y2<0||y1>0&&y2>0) res+=min(abs(y1),abs(y2));//都在上侧或者都在下侧 cout<<res<<endl;
}
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)