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. 第二章 C#基本数据类型

    第一节 1-关键字和标识符关键字:会不同颜色显示标示符:由字母.中文.数字.下划线组成,不能以数字开头,不能是关键字,不能含有特殊符号,如:@,$思考:下列哪些是合法的标识符?a1.1a.a_b._1 ...

  2. CROSS JOIN连接用于生成两张表的笛卡尔集

    将两张表的情况全部列举出来 结果表: 列= 原表列数相加 行= 原表行数相乘     CROSS JOIN连接用于生成两张表的笛卡尔集. 在sql中cross join的使用: 1.返回的记录数为两个 ...

  3. ios 弹出键盘 视图向上平移

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardwillAppear:) name:U ...

  4. Struts2拦截器之ModelDrivenInterceptor

    叙述套路: 1.这是个啥东西,它是干嘛用的? 2.我知道它能干啥了,那它咋个用呢? 3.它能跑起来了,但是它是咋跑起来的是啥原理呢? 一.ModelDriven是个啥?他能做什么? 从前端页面到后端的 ...

  5. 三、jQuery--jQuery实践--瀑布流布局

    实现方法: 1.JavaScript 2.jQuery 3.CSS多栏布局 法一: window.onload=function(){ waterfall('main','pin'); var dat ...

  6. mysql编码设置

    一:mysql字符集 mysql的字符集支持(Character Set Support)有两个类型:字符集(Character set)和连接校对(Collation).对于字符集的支持细化到四个层 ...

  7. IIS网站发布若干问题

    1.Win7 64位 IIS未能加载文件或程序集"System.Data.SQLite"或它的某一个依赖项   未能加载文件或程序集"System.Data.SQLite ...

  8. GPS NEMA 0183协议

    转自:http://www.cnblogs.com/xidongs/archive/2011/02/01/1948689.html 一. NMEA0183标准语句(GPS常用语句)$GPGGA例:$G ...

  9. Quartz:Cron Expressions

    原文地址:http://www.quartz-scheduler.net/documentation/quartz-2.x/tutorial/crontrigger.html 注意: 位也可能是7位, ...

  10. 用康托展开实现全排列(STL、itertools)

    康拓展开: $X=a_n*(n-1)!+a_{n-1}*(n-2)!+\ldots +a_2*1!+a_1*0!$ X=an*(n-1)!+an-1*(n-2)!+...+ai*(i-1)!+...+ ...