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. Mysql Condition /Handler(异常处理)

    关于介绍,可参见:http://www.cnblogs.com/end/archive/2011/04/01/2001946.html. http://blog.csdn.net/rdarda/art ...

  2. Mysql 删除语句

    手册: 14.2.2 DELETE Syntax 单表删除语句:DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name [PARTITION (par ...

  3. java.util.ConcurrentModificationException

    遍历 List 的时候将 item remove 掉会抛出此异常

  4. 初学iPad开发入门

    iPad是一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑MacBook产品之间跟iPhone一样,搭载的是iOS操作系统 iPhone和iPad开发的区别 屏幕的 ...

  5. Android Programming: Pushing the Limits -- Chapter 2: Efficient Java Code for Android

    Android's Dalvik Java 与 Java SE 进行比较 Java代码优化 内存管理与分配 Android的多线程操作 Android’s Dalvik Java 与 Java SE ...

  6. ASP.NET的Cookie和Session

    HTTP属于应用层,HTTP协议一共有五大特点:1.支持客户/服务器模式;2.简单快速;3.灵活;4.无连接;5.无状态. 无状态HTTP协议是无状态的协议.一旦数据交换完毕,客户端与服务器端的连接就 ...

  7. 无废话ExtJs 入门教程三[窗体:Window组件]

    无废话ExtJs 入门教程三[窗体:Window组件] extjs技术交流,欢迎加群(201926085) 1.代码如下: 1 <!DOCTYPE html PUBLIC "-//W3 ...

  8. OCJP(1Z0-851) 模拟题分析(三)over

    Exam : 1Z0-851 Java Standard Edition 6 Programmer Certified Professional Exam 以下分析全都是我自己分析或者参考网上的,定有 ...

  9. 2016"百度之星" - 初赛(Astar Round2A)All X(数学 矩阵)

    All X  Accepts: 1281  Submissions: 7580  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  10. 5-06使用Sql 语句为表添加约束

    约束名的命名规则推荐采用:约束类型_约束列. 为用户表添加约束 ALTER TABLE UserInfo ADD CONSTRALNT PK_UserId PRIMATY REY(UserId) CO ...