传送门:

http://codeforces.com/problemset/problem/598/C

Nearest vectors
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.

Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.

Input

First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.

The i-th of the following n lines contains two integers xi and yi (|x|, |y| ≤ 10 000, x2 + y2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).

Output

Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.

Examples
Input

Copy
4
-1 0
0 -1
1 0
1 1
Output

Copy
3 4
Input

Copy
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output

Copy
6 5

分析:
题意:
给你n个点,问你这些点和原点构成的n个向量中,哪两个向量构成的角最小
做法:
用atan2函数把所有向量与x轴正半轴的夹角求出,排序,俩俩间比较差值即可。 C 语言里long double atan2(long double y,long double x) 返回的是原点至点(x,y)的方位角,
即与 x 轴的夹角。也可以理解为复数 x+yi 的辐角。
返回值的单位为弧度,取值范围为(-PI,PI]。 需要注意的地方:
1.使用long double
2.两两比较的时候,一开始要取最大差值,就是第一个和最后一个的差值
(注意最后一个角度(最大角)和第一个角度(最小角)的角度差可能是负值,要加上2*PI)
才能比较出最小的嘛 code:
#include<bits/stdc++.h>
using namespace std;
typedef long double LB;
#define max_v 100105
#define PI acos(-1)
#define double long double // 使用long double
const int MAXN = 1e5 + ;
struct node
{
double v;
int index;
bool operator < (const node& t)const//按照v升序
{
return v < t.v;
}
} p[MAXN];
bool cmp(node a,node b)
{
return a.v<b.v;
}
int main()
{
int n;
scanf("%d",&n);
int x,y;
for(int i=; i<=n; ++i)
{ scanf("%d %d",&x,&y);
p[i].v=atan2(y,x);
p[i].index=i;
}
sort(p+,p+n+);
int ans1=p[].index;
int ans2=p[n].index;
double v=p[].v+*PI-p[n].v;
for(int i=; i<n; ++i)
{
double temp=p[i+].v-p[i].v;
if(temp<v)
{
v=temp;
ans1=p[i].index;
ans2=p[i+].index;
}
}
printf("%d %d\n",ans1,ans2);
return ;
}

 

CodeForces - 598C Nearest vectors(高精度几何 排序然后枚举)的更多相关文章

  1. CodeForces 598C Nearest vectors

    这题对精度要求很高.用atan2吧... #include<iostream> #include<cstring> #include<cmath> #include ...

  2. codeforces 598C C. Nearest vectors(极角排序)

    题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  3. Educational Codeforces Round 1 C. Nearest vectors 极角排序

    Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...

  4. Educational Codeforces Round 1(C. Nearest vectors)

    题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...

  5. codeforces Gym 100500C C. ICPC Giveaways 排序

    Problem C. ICPC GiveawaysTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1005 ...

  6. Codeforces 558E A Simple Task (计数排序&&线段树优化)

    题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memor ...

  7. codeforces 1284E. New Year and Castle Construction(极角排序+扫描枚举)

    链接:https://codeforces.com/problemset/problem/1284/E 题意:平面上有n个点,问你存在多少组四个点围成的四边形 严格包围某个点P的情况.不存在三点共线. ...

  8. codeforces 101C C. Vectors(数学)

    题目链接: C. Vectors time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  9. CodeForces 682B Alyona and Mex (排序+离散化)

    Alyona and Mex 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/B Description Someone gave ...

随机推荐

  1. rockmongo配置文件config.php

    使用编辑器(比如notepad或者VI/VIM命令)打开RockMongo安装目录下的config.php,所有的配置都在这里. 认证 mongo_auth 和control_auth 在开始使用Ro ...

  2. 数据库和AI的一次火花

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由宗文 发表于云+社区专栏 | 导语 通过历史数据,基于时间序列来预测未来. 我们生活中很多数据是有时间维度的.比如说天气或者股票价格. ...

  3. CF 304B——Calendar——————【年月日计算】

    B - Calendar Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  4. HDU 5222 ——Exploration——————【并查集+拓扑排序判有向环】

    Exploration Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  5. git提交代码报错 trailing whitespace的解决方法

    1. git提交代码报错 trailing whitespace 禁止执行pre-commit脚本 进入到项目目录中 chmod a-x .git/hooks/pre-commit 2.git提交代码 ...

  6. 深入理解JavaScript系列(6):S.O.L.I.D五大原则之单一职责SRP

    前言 Bob大叔提出并发扬了S.O.L.I.D五大原则,用来更好地进行面向对象编程,五大原则分别是: The Single Responsibility Principle(单一职责SRP) The ...

  7. phpstorm主题设置

    毫无疑问,phpstorm很好用,但是安装完成后自带的主题,丑的一匹,所以总结下如何更换主题............. 1.主题下载位置 http://www.phpstorm-themes.com ...

  8. C#字符串替换_无视大小写

    C#里的string.Replace是不能无视大小写的. 首先想到的是正则表达式,在网上查了下,果然有用正则表达式配合一些逻辑运算,实现无视大小写的字符串替换方法.但是正则表达式的方法用起来很麻烦,实 ...

  9. scss-变量分隔符

    scss的变量名可以与css中的属性名和选择器名称相同,包括中划线和下划线. 在使用中划线还是下划线来进行变量分隔完全根据个人喜好. scss完全兼容这两种写法,也就是说scss认为中划线和下划线是完 ...

  10. ACCESS模糊查询注意事项

    ACCESS模糊查询出现的问题,开发中需要注意!在SQL Server中模糊查询通常是这样的Select * from articleTable where authorName like '%jac ...