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
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 v, u as: p(v, u) = sqrt((sv − su)2 + (rv − ru)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 · 105).
In the next n lines there are two integers in each line — si and ri (−108 ≤ si, ri ≤ 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
22 37 6
11 2
35 52 -4-4 2
0
可以把每个小朋友看作是一个个点,所谓p(u,v)就是计算的两个点之间的距离,然后要满足(v, u) ≥ 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
- URAL 2067. Friends and Berries
- URAL 2067 Friends and Berries
- Ural 2067 Friends and Berries 【思维】
- ural 2067 Friends and Berries 数学推理
- URAL 2001. Mathematicians and Berries
- URAL 2001 Mathematicians and Berries (小学数学题)
- money and friends
- A. Dima and Friends
- B. Friends and Presents
- HDU5874 Friends and Enemies
- HDU5874 Friends and Enemies
- HDU5874-Friends and Enemies
- B. Dasha and friends
- Codeforces761B Dasha and friends
- B. Dasha and friends
- Friends and Subsequences
- Friends and Enemies HDU
- Friends and Subsequences
- lmbench3 lat_mem_rd的测试结果记录
- linux学习记录文本编辑
- c++ 正整数拆分成素因子的乘积
- 「信息安全产品」WAF,web应用防火墙
- leetcode 392. Is Subsequence
- URAL 2067. Friends and Berries
- web前端技术
- 已知一个抽象类Shapge,该类中有一个方法GetArea。 要求定义一个Rectangle类,继承Shape类,实现GetArea方法计算矩形面积。
- 线程安全和可重入函数
- C/C++输入输出
- IMWeb训练营作业-----Vue+Bootstrap留言板
- java基础总结(1)
- C++中类的复制构造函数
- 页面制作HTML+CSS基础乱炖