Educational Codeforces Round 1(C. Nearest vectors)
题目链接: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)的更多相关文章
- Educational Codeforces Round 1 C. Nearest vectors 极角排序
Partial Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/ ...
- Educational Codeforces Round 35 A. Nearest Minimums【预处理】
[题目链接]: Educational Codeforces Round 35 (Rated for Div. 2) A. Nearest Minimums time limit per test 2 ...
- [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 ...
- Educational Codeforces Round 6 C. Pearls in a Row
Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...
- Educational Codeforces Round 9
Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...
随机推荐
- UVa 10256 (判断两个凸包相离) The Great Divide
题意: 给出n个红点,m个蓝点.问是否存在一条直线使得红点和蓝点分别分布在直线的两侧,这些点不能再直线上. 分析: 求出两种点的凸包,如果两个凸包相离的话,则存在这样一条直线. 判断凸包相离需要判断这 ...
- UVALive 4287 Proving Equivalences(缩点)
等价性问题,给出的样例为 a->b的形式,问要实现全部等价(即任意两个可以互相推出),至少要加多少个形如 a->b的条件. 容易想到用强连通缩点,把已经实现等价的子图缩掉,最后剩余DAG. ...
- liunx之zip格式的解压命令
zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip unzip -o -d /home/s ...
- Oracle RAC 客户端连接负载均衡(Load Balance)
实现负载均衡(Load Balance)是Oracle RAC最重要的特性之一,主要是把负载平均分配到集群中的各个节点,以提高系统的整体吞吐能力.通常情况下有两种方式来实现负载均衡,一个是基于客户端连 ...
- U1 - A 留在电脑里的字体
U1系列新篇章,实战派!说说常用的字体! U1系列新篇章,实战派!更多干货更多关于软件的使用等即将放出,大家敬请期待!!
- [Everyday Mathematics]20150116
设 $\al_n\geq 0$ 且 $\dps{\vlm{n}\al_n=0}$, 试求 $$\bex \vlm{n}\frac{1}{n}\sum_{k=1}^n \ln\sex{\frac{k}{ ...
- Ui篇--layout_weight体验(实现按比例显示)
在android开发中LinearLayout很常用,LinearLayout的内控件的android:layout_weight在某些场景显得非常重要,比如我们需要按比例显示.android并没用提 ...
- IOS Swizzle(hook)
/////////////////////////////////////////////////////////////////////////////////////////////////// ...
- C ~ char int 等数据转换问题
1,char型数字转换为int型 "; printf(]-');//输出结果为3 2,int转化为char (1)字符串转换成数字,用atoi,atol,atof,分别对应的是整型,long ...
- SSH整合常见错误
spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext ...