Educational Codeforces Round 1 C. Nearest vectors 极角排序
Partial Tree
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/598/problem/C
Description
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.
Sample Input
- 4
-1 0
0 -1
1 0
1 1
Sample Output
- 3 4
HINT
题意
给你n个向量,然后问你角度差最小的两个向量是哪两个
题解:
nlogn极角排序之后,再扫一遍就好了
但是这道题会挂精度,所以直接把所有的double改成long double就过了。。
代码
- #include<iostream>
- #include<stdio.h>
- #include<math.h>
- #include<vector>
- #include<algorithm>
- using namespace std;
- vector<pair<long double,int> > K;
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=;i<n;i++)
- {
- long double x,y;cin>>x>>y;
- pair<long double,int> KK;
- KK.first = atan2(y,x),KK.second = i+;
- K.push_back(KK);
- }
- sort(K.begin(),K.end());
- long double ans1 = *acos(-1.0);
- int ans2 = ,ans3 = ;
- for(int i=;i<n;i++)
- {
- long double t = (K[(i+)%n].first-K[i].first);
- if(t<)t+=acos(-1.0)*;
- if(t<ans1)
- {
- ans1 = t;
- ans2 = K[i].second;
- ans3 = K[(i+)%n].second;
- }
- }
- printf("%d %d\n",ans2,ans3);
- }
Educational Codeforces Round 1 C. Nearest vectors 极角排序的更多相关文章
- Educational Codeforces Round 1(C. Nearest vectors)
题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...
- Educational Codeforces Round 35 A. Nearest Minimums【预处理】
[题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...
- codeforces 598C C. Nearest vectors(极角排序)
题目链接: C. Nearest vectors time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Educational Codeforces Round 25 E. Minimal Labels 拓扑排序+逆向建图
E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [Educational Codeforces Round 16]B. Optimal Point on a Line
[Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
随机推荐
- Java中的面向接口编程
面向接口编程是很多软件架构设计理论都倡导的编程方式,学习Java自然少不了这一部分,下面是我在学习过程中整理出来的关于如何在Java中实现面向接口编程的知识.分享出来,有不对之处还请大家指正. 接口体 ...
- MySQL 索引详解
本文介绍了数据库索引,及其优.缺点.针对MySQL索引的特点.应用进行了详细的描述.分析了如何避免MySQL无法使用,如何使用EXPLAIN分析查询语句,如何优化MySQL索引的应用. 索引是一种特殊 ...
- 音频PCM格式
经常见到这样的描述: 44100HZ 16bit stereo 或者 22050HZ 8bit mono 等等. 44100HZ 16bit stereo: 每秒钟有 44100 次采样, 采样数据用 ...
- UVA 10054 The Necklace
完全就是哭瞎的节奏···QAQ 又是图论··· 题意:有一种项链,每个珠子上有两种颜色,相同颜色的两颗珠子的两头相连,如果能连成环输出珠子的顺序,不能连成环输出"some beads may ...
- 标准Web系统的架构分层[转]
标准Web系统的架构分层 – 转载请注明出处 1.架构体系分层图 在上图中我们描述了Web系统架构中的组成部分.并且给出了每一层常用的技术组件/服务实现.需要注意以下几点: 系统架构是灵活的,根据需求 ...
- duilib修复ActiveXUI控件bug,以支持flash透明动态背景
转载请说明原出处,谢谢~~ 昨天在QQ控件里和同学说起QQ2013登陆窗体的开发,从界面角度考虑,单单一个登陆界面是很容易做出来的.腾讯公司为了 防止各种盗号行为可谓煞费苦心,QQ2013采用了动态背 ...
- 使用Qmake在树莓派上开发Opencv程序
Qt 安装 PC 端 下载安装即可 https://mirrors.ustc.edu.cn/qtproject/official_releases/qt 树莓派:Qt开发套件和opencv安装sud ...
- 根据给定的日期给 dateEdit 控件增加颜色
private void dateEdit1_DrawItem(object sender, DevExpress.XtraEditors.Calendar.CustomDrawDayNumberCe ...
- 游戏设计模式:Subclass Sandbox模式,以及功能方法集的设计思考
书中总结出这种 Subclass Sandbox 的设计模式 Game Design Patterns: Subclass Sandbox 这种模式要点有两点: 在基类中实现各种功能性方法供子类调用 ...
- Python之正则
从学习Python至今,发现很多时候是将Python作为一种工具.特别在文本处理方面,使用起来更是游刃有余. 说到文本处理,那么正则表达式必然是一个绝好的工具,它能将一些繁杂的字符搜索或者替换以非常简 ...