传送门:

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. MySql Unknown column 的解决方案

    解决方案: 有很多使用Mysql的用户可能都会遇到这个问题,明明表中这个列存在,为什么在查询的时候说找不到这个列名呢? 我遇到的原因就是列名前面含有空格:如下 create table student ...

  2. document.write与document.getElementById.innterHTML的区别

    <html> <head> <meta charset="utf-8"> <script> var tmp = "< ...

  3. nyoj 220——推桌子——————【贪心】

    推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Computer Maker) Company has re ...

  4. C#请求http向网页发送数据,网页接收

    首先,我们需要的是什么东西? 用POST方式请求http,给网页传输数据,网页接收到数据之后,把数据存储到数据库中. 1.首先请求http,建立连接,把转码过的数据传输过去 2.网页接收数据,在转码之 ...

  5. Sql server 操作笔记

    (1)更改字段类型 (2)添加字段 alter table class add InKinDate intEXECUTE sp_addextendedproperty N'MS_Description ...

  6. 【Q】类和对象:游戏角色开发(角色介绍)

    案例情景:某公司要开发新游戏,请用面向对象的思想设计英雄类.怪物类和武器类. 编写测试类,创建英雄对象.怪物对象和武器对象,并输出各自的信息. 其中设定分别如下: 1.英雄类 属性:英雄名字.生命值. ...

  7. oracle学习篇二:常用SQL

    ------------------------1.简单的SQL查询--------------------------select * from emp;select empno,ename,job ...

  8. angular2-模板驱动表单

    app.module.ts 导入 FormsModule  import { NgModule } from '@angular/core'; import { BrowserModule } fro ...

  9. Web开发——前后台异步调用

    做web开发,最头疼的.最核心的部分或许就应该是前后台交互了,之前一直没弄明白,每次都不知道该如何去做.最近由于开发需要,加上有些朋友问起这个问题,不得不再次摸索前后台交互的方法.功夫不负有心人,总算 ...

  10. Matlab GUI选项卡

    1.在这个网址下载一个工具包,里面应该有四个文件:tabselectionfcp.p.tabselectionfcn.m.tabpanel.p和tabpanel.m,显然代码用.p格式进行加密了. 2 ...