传送门:

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. hdu 5242——Game——————【树链剖分思想】

    Game Time Limit:1500MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status  ...

  2. C++程序设计基础(3)条件语句和循环语句

    注:读<程序员面试笔记>笔记总结 1.知识点 1.1条件语句 (1)if……:(2)if……else……:(3)if……else if……:(4)switch(){case ():brea ...

  3. textarea的实现

    由于限制字数是用原有的 maxlength会有问题,所以用一般会用js控制,今天用到三种: (一)html: <body> <form name=myform action=&quo ...

  4. jqGrid -treeGrid 按需加载

    Load Rows On Demand (AJAX) 参考:http://www.guriddo.net/demo/treegridjs/

  5. Node.js之Buffer

    JavaScript 语言自身只有字符串数据类型,没有二进制数据类型.但在处理像TCP流或文件流时,必须使用到二进制数据.因此在 Node.js中,定义了一个 Buffer 类,该类用来创建一个专门存 ...

  6. Python3.4 获取百度网页源码并保存在本地文件中

    最近学习python 版本 3.4 抓取网页源码并且保存在本地文件中 import urllib.request url='http://www.baidu.com' #上面的url一定要写明确,如果 ...

  7. print控制台输出带颜色文字方法

    在python开发的过程中,经常会遇到需要打印各种信息.海量的信息堆砌在控制台中,就会导致信息都混在一起,降低了重要信息的可读性.这时候,如果能给重要的信息加上字体颜色,那么就会更加方便用户阅读了. ...

  8. iDempiere 使用指南 系统安装 以及 virtualbox虚拟机下载

    Created by 蓝色布鲁斯,QQ32876341,blog http://www.cnblogs.com/zzyan/ iDempiere官方中文wiki主页 http://wiki.idemp ...

  9. iPython与notebook的基本用法

    1 Ipython 安装 pip install ipython 2 Notebooke 基本用法 启动ipython使用ipython 启动notebook 使用 ipython notebook ...

  10. Android Studio笔记之快捷键

    Android Studio h2{ color: #4abcde; } pre{ background-color: #f8f8f8; border: solid 1px #ccc; border- ...