C. Connect the Points(计算几何)(找统一规律)

原题链接:

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';
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值