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 si and 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

input output
2
2 3
7 6
1
1 2
3
5 5
2 -4
-4 2
0
Problem Author: Alexey Danilyuk (prepared by Alexey Danilyuk, Alexander Borzunov)
Problem Source: Ural Regional School Programming Contest 2015
Difficulty: 245
 
题意:给n个点,
p(vu) = sqrt((sv − su)^2 + (rv − ru)^2)
p(v,u,w) = (p(v,u) + p(v,w) + p(u,w)) / 2
要求找出p(vu) ≥ p(v,u,w) 的对数
分析:
变形一下,根据三角形两边之和大于第三边的理论。。。
显然当且仅当n个点共线才有答案
 
 #include <iostream>
#include <cstdio>
using namespace std;
#define INF (1000000001) const int N = ;
int n;
typedef long long LL;
struct Point
{
LL x, y;
} arr[N]; inline void input()
{
cin >> n;
for(int i = ; i <= n; i++)
cin >> arr[i].x >> arr[i].y;
} inline LL multi(Point o, Point a, Point b)
{
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
} inline void solve()
{
for(int i = ; i <= n; i++)
if(multi(arr[], arr[], arr[i]) != )
{
cout << << "\n";
return;
} int x = , y = ;
for(int i = ; i <= n; i++)
{
if(arr[i].x < arr[x].x || (arr[i].x == arr[x].x && arr[i].y < arr[x].y)) x = i;
if(arr[i].x > arr[y].x || (arr[i].x == arr[y].x && arr[i].y > arr[y].y)) y = i;
}
cout << << "\n";
cout << x << " " << y << "\n";
} int main()
{
ios::sync_with_stdio();
input();
solve();
return ;
}

ural 2067. Friends and Berries的更多相关文章

  1. URAL 2067 Friends and Berries (推理,数学)

    题意:给定 n 个人,每个人两个值s, r,要满足,p(v, u) = sqrt((sv − su)^2 + (rv − ru)^2), p(v,u,w) = (p(v,u) + p(v,w) + p ...

  2. Friends and Berries URAL - 2067 (计算三点共线和计算的时候的注意点)

    题目链接:https://cn.vjudge.net/problem/URAL-2067 具体思路:判断三点共线就可以了,只有一对点能满足,如果一对就没有那就没有满足的. 在计算的时候,要注意,如果是 ...

  3. 福利到!Rafy(原OEA)领域实体框架 2.22.2067 发布!

    距离“上次框架完整发布”已经过去了一年半了,应群中的朋友要求,决定在国庆放假之际,把最新的框架发布出来,并把帮助文档整理出来,这样可以方便大家快速上手.   发布内容 注意,本次发布,只包含 Rafy ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

随机推荐

  1. java动态生成excel打包下载

    @SuppressWarnings("unchecked") public String batchExport() throws DBException{ @SuppressWa ...

  2. Innodb之监控Buffer pool Load progress

    你可以使用PERFORMANCE SCHEMA中的相关信息监控BUFFER POOL状态加载进程. 1. 启用 stage/innodb/buffer pool load instrument: 2. ...

  3. Navicat 回复 psc 文件 Mysql

    在mysql 中回复 psc文件 的时候 只能一步步来,先在navicat中建一个空数据库,然后点击有上角的备份==>回复备份==> 找到psc文件==> 注意此时不要急于点击 开始 ...

  4. web项目没有run on server时..

    文章转载至:http://blog.csdn.net/hongchangfirst/article/details/7722703 web项目没有run on server 1.首先确保正确安装Tom ...

  5. iOS - 线程管理

    iOS开发多线程篇—GCD的常见用法 一.延迟执行 1.介绍 iOS常见的延时执行有2种方式 (1)调用NSObject的方法 [self performSelector:@selector(run) ...

  6. js获取url参数值(HTML之间传值)

    <h3>未设置设备: <a href="javascript:addTab('设备列表','PKE_DeviceContent/PKE_DeviceContent.aspx ...

  7. 关于Java反射机制的几个问题

    >>如何在运行时确定对象类型 运行时类型识别(Run-time Type Identification, RTTI)主要有两种方式, 一种是在编译时和运行时已经知道了所有的类型,另外一种是 ...

  8. Android4.4 以太网和DHCP启动过程介绍

    转自:http://blog.csdn.net/wlwl0071986/article/details/51451843 Android4.4已经加入了以太网的支持.现在对以太网的初始化流程.网络策略 ...

  9. 在Win7 64位注册ActiveX控件

    首先必须以管理员身份运行cmd.exe,即在cmd.exe右键选择以管理员身份运行.    目前共有两个存在网络盘的文件需要注册,一个dll,一个ocx.    开始时将两个文件都拷贝到c:\wind ...

  10. MVC中数据的内部校验

    针对MVC中实例类型的修饰,我们可以采用DataAnnotations类来完成,该类所处的命名空间是System.ComponentModel.DataAnnotations; 一.通过开类型,能够修 ...