You are given three points on a plane. You should choose some segments on the plane that are parallel to coordinate axes, so that all three points become connected. The total length of the chosen segments should be the minimal possible.
Two points aa and bb are considered connected if there is a sequence of points p0=a,p1,…,pk=bp0=a,p1,…,pk=b such that points pipi and pi+1pi+1 lie on the same segment.
Input
The input consists of three lines describing three points. Each line contains two integers xx and yy separated by a space — the coordinates of the point (−109≤x,y≤109−109≤x,y≤109). The points are pairwise distinct.
Output
On the first line output nn — the number of segments, at most 100.
The next nn lines should contain descriptions of segments. Output four integers x1x1, y1y1, x2x2, y2y2 on a line — the coordinates of the endpoints of the corresponding segment (−109≤x1,y1,x2,y2≤109−109≤x1,y1,x2,y2≤109). Each segment should be either horizontal or vertical.
It is guaranteed that the solution with the given constraints exists.
Example
input
Copy
1 1 3 5 8 6
output
Copy
3 1 1 1 5 1 5 8 5 8 5 8 6
Note
The points and the segments from the example are shown below.
思路:
1,找统一规律,分的太细容易出事
2,找中心轴,两端的点向中心轴去连,不怕段多,就要长度最小。
代码:
struct node{
int x,y;
}dd[4];
bool cmp(node a,node b){
if(a.x!=b.x)
return a.x<b.x;
else return a.y>b.y;
}
void solve() {
read(dd[1].x);read(dd[1].y);
read(dd[2].x);read(dd[2].y);
read(dd[3].x);read(dd[3].y);
sort(dd+1,dd+4,cmp);
sort(dd+1,dd+4,cmp);
int l=dd[1].y,r=dd[1].y;
//找中心轴,化简分类
for(int i=1;i<=3;++i){
l=min(l,dd[i].y);
r=max(r,dd[i].y);
}
if(l==r){
cout<<2<<'\n';
}else{
cout<<3<<'\n';
cout<<dd[2].x<<' '<<l<<' '<<dd[2].x<<' '<<r<<'\n';
}
for(int i=1;i<=3;++i){
if(i==2)continue;
cout<<dd[i].x<<' '<<dd[i].y<<' '<<dd[2].x<<' '<<dd[i].y<<'\n';
}
}