Gym - 101063K - Dire, Dire Docks - 2021-03-09

https://vjudge.z180.cn/contest/425096#problem/K
https://codeforces.com/gym/101063/problem/K

Half a century after the Mars arrival by GEMA, we are finally here. The mission is finally starting to build artificial rivers on mars.

That is possibly the most important event on Mars since the GEMA arrival.

In order to carry on with it, the mission have mapped the surface as 2-dimensional plane, and has identified N points in it that are going to work as reference points to build a river system. There will be a dock constructed in each of these points to help on transportation efforts and collect data for the mission.

The goal of the mission is to connect all the docks with rivers. The lead researcher of the team responsible for that, doctor Maya Waters, has identified the main requirements to build a healthy river system. These are:

  • There are N docks. There should be a way to navigate between any two docks only through water;
  • he system must have exactly N rivers - no more, no less;
  • At most four rivers can meet at any single dock;
  • Any river should flow in a straight line between points A and B;
  • There should be no river crossings apart from the rivers meeting at docks. Note that a river passing through a dock counts as a crossing.

Help doctor Maya figure out which points to connect to build such river system and finally Make Mars Wet Again!

Input

Input begins with N (3 ≤ N ≤ 103), the number of points. Follows N lines, each with two integers xi, yi ( - 109 ≤ xi, yi ≤ 109), the coordinates of the pivotal points.

Output

Output N lines. In each line, output two integers , a and b - the indexes of the pivotal points that must be connected by a river. Indexing begins in 1. If there are multiple solutions, output any.

If it is an impossible task, output -1.

Examples

Input

5
-1 0
2 3
3 2
5 4
6 1

Output

3 2
3 4
5 3
1 5
2 4

Input

3
0 0
1 2
3 6

Output

 -1
#include <bits/stdc++.h>
using namespace std;

/*
在n个点中找出没有交叉的n条线
首先按照大小排序:i与i-1 就是n-1条没有交叉的线
第n条线:与 i=1的点的斜率最大或最小的点(注意不能是i=2的点) 
输出-1的情况:与 i=1 的斜率最大、最小的点是同一个点的时候(也就是所有点的斜率都相等)
*/


const int mxx=0x3f3f3f3f;
const int N=3e3+10;

struct node
{
    int x,y,id;
} st[N];

int cmp(struct node a,struct node b)
{
    if(a.x==b.x) return a.y<b.y;
    return a.x<b.x;
}

double get(int x,int y)
{
    int tx=st[x].x-st[y].x;
    int ty=st[x].y-st[y].y;
    return ty*1.0/tx;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>st[i].x>>st[i].y,st[i].id=i;
    sort(st+1,st+n+1,cmp);

    double pink=mxx,pxnk=-mxx;
    int pint,pxnt;
    
/*
找最大、最小斜率的时候,要从头开始找
不能从i=3开始:
如果i=2是最大的斜率,假设i=5是次大的,i=7是最小的
那么会输出1 5 但与 第2点 会有交叉
*/
    for(int i=2; i<=n; i++)
    {
        double  t=get(1,i);
        if(t>pxnk)
            pxnk=t,pxnt=st[i].id;
        if(t<pink)
            pink=t,pint=st[i].id;
    }

    if(pint==pxnt) cout<<"-1"<<endl;
    else
    {
        for(int i=2; i<=n; i++)
            cout<<st[i-1].id<<' '<<st[i].id<<endl;

        int pp=min(pint,pxnt);
        if(pp==st[2].id) pp=max(pint,pxnt);
        cout<<st[1].id<<" "<<pp<<endl;
    }

    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值