传送门:

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. Android开发:使用Fragment改造TabActivity

    TabActivity在API 13(Android 3.2)被标记为过期,需要使用Fragment来实现,Fragment是Android 3.0引入的一个概念,主要就是为了适应各种不同的屏幕大小( ...

  2. sublime的reopen with encoding和reload with encoding区别

    首先必需要明白一点,sublime无论以什么编码格式打开文本(以什么编码格式来理解文本文件中的二进制数据),都会把它转为utf-8再显示到屏幕中,这个过程称作解码.其实不当当是sublime,其实任何 ...

  3. jgrid 选择器 C#控件

    一.RadioButtonList html代码: <asp:RadioButtonList ID="rlPlan" runat="server" Rep ...

  4. 利用pandas生成csv文件

    # -*- coding:UTF-8 -*- import json from collections import OrderedDict with open('dns_status.json',' ...

  5. 从数组去重这个函数来体验es6的高效率

    前几天碰到一个题目,要求是这样的. 题目描述 为 Array 对象添加一个去除重复项的方法 示例1 输入 [false, true, undefined, null, NaN, 0, 1, {}, { ...

  6. 学习安卓开发过程中遇到关于R.Java文件的问题

    在学习安卓开发过程时,遇到R.java生成问题,总结几个方法解决. 1.首先必须做的就是检查代码的正确性,存在错误的代码,不编译生成R.java 2.右键点项目,选择 Android Tools -& ...

  7. python搭建本地服务器

    python搭建本地服务器 python3以上版本 'python3 -m http.server 8000' 默认是8000端口,可以指定端口,打开浏览器输入http://127.0.0.1:800 ...

  8. java编程中'为了性能'一些尽量做到的地方

    原文地址:http://blog.csdn.NET/m13666368773/article/details/7796924 最近的机器内存又爆满了,出了新增机器内存外,还应该好好review一下我们 ...

  9. 【代码笔记】Java连连看项目的实现(2)——JTable 、TableModel的使用

    博客有时间就写写,所以一篇可能会拆成很多篇,写完后计划再合在一起. 首先肯定是要实现连连看的界面. 先准备连连看要的图片.. “LianLianKan”就是项目名称. 当然,如果小白看我的博客想学到什 ...

  10. 使用git版本管理工具

    1.(1)正常提交:git add 提交文件 git init   //git init之后建立一个.gitignore可以避免node_modules这类文件夹提交 git add . git co ...