题目链接:http://codeforces.com/problemset/problem/598/C

  题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y != 0)。求当两个点与原点形成的角度最小时,是哪两个点。

  先介绍atan2这个函数,atan2(double y,double x) 其中y代表已知点的Y坐标 同理x ,返回值是此点与远点连线与x轴正方向的夹角,这样它就可以处理四个象限的任意情况了,它的值域相应的也就是-180~180了。

  我觉得最好还是用atan2这个函数,求出与x正轴的角度,然后从小到大排序,处理相邻的两个点的角度(后面的减前面的),最后处理第一个和最后一个点角度,最好乘上个1000,精度问题...

  代码如下:

  

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std;
const int MAXN = 1e5 + ;
double PI = acos(-) , M = ;
struct data {
double x , y , ang;
int id;
}a[MAXN]; bool cmp(data a , data b) {
return a.ang < b.ang;
}
//min()函数只能用于整数
double MIN(double x , double y) {
if(x > y)
return y;
return x;
} int main()
{
int n;
ios::sync_with_stdio(false);
while(cin >> n) {
for(int i = ; i < n ; i++) {
cin >> a[i].x >> a[i].y;
a[i].id = i + ;
a[i].ang = atan2(a[i].y , a[i].x) * 180.0 * M / PI;
}
sort(a , a + n , cmp);
int id1 , id2;
double Min = 100000000.0 , temp;
for(int i = ; i < n ; i++) {
temp = a[i].ang - a[i - ].ang;
temp = MIN(temp , * M - temp);
if(Min > temp) {
id1 = a[i - ].id;
id2 = a[i].id;
Min = temp;
}
}
temp = a[n - ].ang - a[].ang;
temp = MIN(temp , * M - temp);
if(temp < Min) {
cout << a[].id << " " << a[n - ].id << endl;
}
else {
cout << id1 << " " << id2 << endl;
}
}
}

Educational Codeforces Round 1(C. Nearest vectors)的更多相关文章

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

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

  2. Educational Codeforces Round 35 A. Nearest Minimums【预处理】

    [题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...

  3. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  4. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  5. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  6. [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 ...

  7. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  8. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  9. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

随机推荐

  1. HDU 1255 覆盖的面积 (扫描线 线段树 离散化 矩形面积并)

    题目链接 题意:中文题意. 分析:纯手敲,与上一道题目很相似,但是刚开始我以为只是把cnt>=0改成cnt>=2就行了,. 但是后来发现当当前加入的线段的范围之前 还有线段的时候就不行了, ...

  2. HDU 1397 Goldbach's Conjecture【素数打表】

    题意:给出n,问满足a+b=n且a,b都为素数的有多少对 将素数打表,再枚举 #include<iostream> #include<cstdio> #include<c ...

  3. BZOJ2229: [Zjoi2011]最小割

    题解: 真是一道神题!!! 大家还是围观JZP的题解吧(网址找不到了...) 代码: #include<cstdio> #include<cstdlib> #include&l ...

  4. javascript倒计时代码

    其实就是用两个时间戳相减,余数转换为日期,就是所剩的年月日时分秒,不过年份-1970 $scope.timerID = null; $scope.timerRunning = false;$scope ...

  5. Java中hashcode,equals和==

    hashcode方法返回该对象的哈希码值. hashCode()方法可以用来来提高Map里面的搜索效率的,Map会根据不同的hashCode()来放在不同的位置,Map在搜索一个对象的时候先通过has ...

  6. [反汇编练习] 160个CrackMe之005

    [反汇编练习] 160个CrackMe之005. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  7. HDU 4607 Park Visit (DP最长链)

    [题目]题意:N个城市形成一棵树,相邻城市之间的距离是1,问访问K个城市的最短路程是多少,共有M次询问(1 <= N, M <= 100000, 1 <= K <= N). [ ...

  8. linux lnmp编译安装

    关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled ...

  9. 系统性能监控之vmstat和iostat命令

    这篇文章主要介绍一些Linux性能检测相关的命令. vmstat和iostat的两个命令可以运行在主流的Linux/Unix操作系统上. 如果vmstat和iostat命令不能再你的电脑上运行,请安装 ...

  10. 《C++ Primer 4th》读书笔记 第5章-表达式

    原创文章,转载请注明出处: http://www.cnblogs.com/DayByDay/p/3912114.html