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\),问最多能抽出多少个数, ...
随机推荐
- build path功能详解
在项目上右键>Build path>Config build path “web project”中,一般把"src"设置为source folder,把WEB-INF ...
- js判断浏览器类型和内核
function judge() { var sUserAgent = navigator.userAgent.toLocaleLowerCase(); var isLinux = (String(n ...
- Web Api 如何做上传文件的单元测试
代码如下: //--------上传------------ HttpClient client = new HttpClient(); #region MultipartFormDataConten ...
- Java中hashcode,equals和==
hashcode方法返回该对象的哈希码值. hashCode()方法可以用来来提高Map里面的搜索效率的,Map会根据不同的hashCode()来放在不同的位置,Map在搜索一个对象的时候先通过has ...
- LeetCode Contains Duplicate (判断重复元素)
题意: 如果所给序列的元素不是唯一的,则返回true,否则false. 思路: 哈希map解决. class Solution { public: bool containsDuplicate(vec ...
- LeetCode: Combination Sum I && II && III
Title: https://leetcode.com/problems/combination-sum/ Given a set of candidate numbers (C) and a tar ...
- 最简单的视音频播放示例8:DirectSound播放PCM
本文记录DirectSound播放音频的技术.DirectSound是Windows下最常见的音频播放技术.目前大部分的音频播放应用都是通过DirectSound来播放的.本文记录一个使用Direct ...
- String.IsNullOrEmpty 方法
参数 value:一个String引用 返回值 如果 value 参数为 空引用(在 Visual Basic 中为 Nothing) 或空字符串 (""),则为 true:否则为 ...
- 嵌入式 hi3518c下ramdisk文件系统与文件系统烧写以及uboot中change-the-env
NULL RAM : mkdir ramdisk_test 临时挂在点 dd if=/dev/zero of=123 bs=1k count=10000 建立空硬盘 losetup /dev/loo ...
- POJ 1094 Sorting It All Out
题意:给出m对关于n个字母的小于关系,输出通过这些关系能得到的结论,如果可以排序就输出至少知道第几个关系时就可以知道顺序,从小到大输出顺序:如果产生歧义就输出在第几个关系时出现歧义,如果不能得出准确的 ...