Come Together

Come Together
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 AB, 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 (1t1041≤≤104) — the number of test cases.

The first line of each test case contains two integers xA and yA (1xA,yA1081≤,≤108) — the position of cell A, where both Bob and Carol are right now.

The second line contains two integers xB and yB (1xB,yB1081≤,≤108) — the position of cell B (Bob's house).

The third line contains two integers xC and yC (1xC,yC1081≤,≤108) — the position of cell C (Carol's house).

Additional constraint on the input: the cells AB, 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 using namespace std; const int 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; } return 0; }
复制代码

 

 

__EOF__

本文作者Sakurajimamai
本文链接https://www.cnblogs.com/o-Sakurajimamai-o/p/17547715.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   o-Sakurajimamai-o  阅读(32)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
-- --
点击右上角即可分享
微信分享提示