您的位置:首页 > 其它

E - Friends and Berries URAL - 2067(三点共线)

2017-12-06 11:38 381 查看
There is a group of n children. According to a proverb, every man to his own taste. So the children value strawberries and raspberries differently. Let’s say that i-th child rates his attachment to strawberry as s i and his attachment to raspberry as r i.
According to another proverb, opposites attract. Surprisingly, those children become friends whose tastes differ.
Let’s define friendliness between two children v, u as: p( v, u) = sqrt(( s v − s u) 2 + ( r v − r u) 2)
The friendliness between three children v, u, w is the half the sum of pairwise friendlinesses: p( v, u, w) = ( p( v, u) + p( v, w) + p( u, w)) / 2
The best friends are that pair of children v, u for which v ≠ u and p( v, u) ≥ p( v, u, w) for every child w. Your goal is to find all pairs of the best friends.


Input

In the first line there is one integer n — the amount of children (2 ≤ n ≤ 2 · 10 5).

In the next n lines there are two integers in each line — s i and r i (−10 8 ≤ s i, r i ≤ 10 8).

It is guaranteed that for every two children their tastes differ. In other words, if v ≠ u then s v ≠ s u or r v ≠ r u.

Output

Output the number of pairs of best friends in the first line.

Then output those pairs. Each pair should be printed on a separate line. One pair is two numbers — the indices of children in this pair. Children are numbered in the order of input starting from 1. You can output pairs in any order. You can output indices of the pair in any order.

It is guaranteed that the amount of pairs doesn’t exceed 10 5.

Example

input output

2
2 3
7 6

1
1 2

3
5 5
2 -4
-4 2

0


题意:题目的意思就是说找到两个点,使得dis(u,v)>=dis(u,w)+dis(w,v),仔细想一想其实不可能大于(构成三角形的条件)我们判断所有点是否共线,如果是,就输出线段的两个端点。就是说,最多只有一种情况,即三(多)点共线,否则就为0.

#include <bits/stdc++.h>
using namespace std;
struct node
{
int x,y;
int id;
}s[301010];
int cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
int n;
cin>>n;
int tot=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&s[i].x,&s[i].y);
s[i].id=i+1;
}
sort(s,s+n,cmp);
int ok=0;
for(int i=1;i<n-1;i++)
{
if(abs(s[i].x-s[0].x)*abs(s[n-1].y-s[i].y)!=abs(s[i].y-s[0].y)*abs(s[n-1].x-s[i].x))///平行线段成对应比例
{ ok=1;break;}
}
if(ok==0)
{
printf("1\n");
printf("%d %d\n",s[0].id,s[n-1].id );
}
else printf("0\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: