URAL 2067. Friends and Berries

来源:互联网 发布:网络辱骂警察 编辑:程序博客网 时间:2024/05/22 15:02

原题链接:http://acm.timus.ru/problem.aspx?space=1&num=2067


2067. Friends and Berries

Time limit: 2.0 second
Memory limit: 64 MB
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 siand his attachment to raspberry as ri.
According to another proverb, opposites attract. Surprisingly, those children become friends whose tastes differ.
Let’s define friendliness between two children vu as: p(vu) = sqrt((sv − su)2 + (rv − ru)2)
The friendliness between three children vuw 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 vu for which v ≠ u and p(vu) ≥ 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 · 105).
In the next n lines there are two integers in each line — si and ri (−108 ≤ siri ≤ 108).
It is guaranteed that for every two children their tastes differ. In other words, if v ≠ u then sv ≠ su or rv ≠ ru.

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 105.

Samples

inputoutput
22 37 6
11 2
35 52 -4-4 2
0



可以把每个小朋友看作是一个个点,所谓p(u,v)就是计算的两个点之间的距离,然后要满足(vu) ≥ p(v,u,w),就是证明对于任意三角形,其中一边l(u,v)>=三角形周长和的一半,但是我们知道,三角形任意一边一定小于周长和的一半(证明:∵a+b>c
∴a+b+c>2c     ∴(a+b+c)/2>c ;),所以一定是三点共线的时候才满足上述条件,并且满足条件的u,v两点在两边,所以若有满足的情况,则只有一种(点不重复)。


// URAL2067_Friends and Berries.cpp : 定义控制台应用程序的入口点。//#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;struct node{int x, y;int num;bool operator<(const node &a)const{if (x == a.x)return y < a.y;return x < a.x;}}a[200005];int main(){int n, i, j;scanf("%d", &n);for (i = 0; i < n; i++){scanf("%d%d", &a[i].x, &a[i].y);a[i].num = i + 1;}sort(a, a + n);int kx = a[1].x - a[0].x;int ky = a[1].y - a[0].y;for (i = 2; i < n; i++){int kkx = a[i].x - a[i - 1].x;int kky = a[i].y - a[i - 1].y;if (kx*kky != ky*kkx){printf("0\n");return 0;}}printf("1\n%d %d\n", a[0].num, a[n - 1].num);return 0;}



0 0
原创粉丝点击