题目链接: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. centos6.5安装mongodb

    搜索正面五个文件,由于MongoDB的redhat国外镜像访问非常慢,下载安装suse版本并安装: mongodb-org-2.6.6-1.i686.rpm mongodb-org-mongos-2. ...

  2. 循环中不要放入openSession()

    for(Shop s:list) { System.out.println(s.getName()); String sql="select shopId,sum(ele_bank+ele_ ...

  3. 制作SM2证书

    前段时间将系统的RSA算法全部升级为SM2国密算法,密码机和UKey硬件设备大都同时支持RSA和SM2算法,只是应用系统的加解密签名验证需要修改,这个更改底层调用的加密动态库来,原来RSA用的对称加密 ...

  4. Python3 学习第三弹:异常情况如何处理?

    python 的处理错误的方式: 1> 断言 assert condition 相当于 if not condition: crash program 断言设置的目的就是因为与其让程序晚点崩溃, ...

  5. fil_system_struct

    /** The tablespace memory cache */ typedef struct fil_system_struct fil_system_t; /** The tablespace ...

  6. UVa 11584 Partitioning by Palindromes

    题意: 给出一个字符串,求最少能划分成多少个回文子串. 分析: d[i] = min{d[j] + 1 | s[j+1]...s[i]是回文串} d[i]表示前 i 个字符最少能分割的回文子串的个数 ...

  7. BZOJ3759: Hungergame

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=3759 题解:只想到了两种情况必胜,没有推广T_T 先说一下我想到了两种情况: 1)异或和为0  ...

  8. PhoneGap 安装体验

    npm -v #显示版本,检查npm 是否正确安装. npm install express #安装express模块 npm install -g express #加上 -g 启用global安装 ...

  9. 在win7系统下使用TortoiseGit(乌龟git)简单操作Git@OSC

    非常感谢OSC提供了这么好的一个国内的免费的git托管平台.这里简单说下TortoiseGit操作的流程.很傻瓜了 首先你要准备两个软件,分别是msysgit和tortoisegit,乌龟还可以在下载 ...

  10. 设置Android默认锁定屏幕旋转

    /********************************************************************************** * 设置Android默认锁定屏 ...