Educational Codeforces Round 1-积角排序-C. Nearest vectors
来源:互联网 发布:淘宝手机模板免费下载 编辑:程序博客网 时间:2024/05/16 13:55
http://codeforces.com/contest/598/problem/C
给定一些向量,问你两者之间对应角最小的是哪个。
积角排序,注意最大的和最小的差别可能很大,但是角度是有周期的,所以减去 2π 之后仍然可能是最小的。其他就可以了。
还有 atan2是 (y,x)形式
#include <bits/stdc++.h>using namespace std;bool cmp2(pair<pair<int,int>,pair<int,long double> > a,pair<pair<int,int>,pair<int,long double> > b){ return a.second.second<b.second.second;}int main(){ int t; double a,b; vector<pair<pair<int,int>,pair<int,long double> > >v; scanf("%d",&t); for(int i=0;i<t;i++){ scanf("%lf%lf",&a,&b); v.push_back(make_pair(make_pair(a,b),make_pair(i+1,atan2(b,a)))); } sort(v.begin(),v.end(),cmp2); //for(int i=0;i<v.size();i++) //printf("%.0f %.0f %.0f\n",v[i].first.first,v[i].first.second,v[i].second); long double ans1=2*acos(-1.0); int ans2; int ans3; for(int i=0;i<v.size()-1;i++) { long double tt = v[i+1].second.second-v[i].second.second; if(tt<0)tt+=acos(-1.0)*2; if(tt<ans1) { ans1 = tt; ans2 = v[i].second.first; ans3 = v[i+1].second.first; } } printf("%d %d\n",ans2,ans3); return 0;}
阅读全文
0 0
- Educational Codeforces Round 1-积角排序-C. Nearest vectors
- Educational Codeforces Round 1 C.Nearest vectors(排序)
- Educational Codeforces Round 1 C. Nearest vectors
- Educational Codeforces Round 1 C. Nearest vectors
- Educational Codeforces Round 1 C - Nearest vectors
- Educational Codeforces Round 1C. Nearest vectors
- Educational Codeforces Round 1C. Nearest vectors(极角排序+long double 精度)
- Educational Codeforces Round 1 C Nearest vectors(极角排序)
- Educational Codeforces Round 1 C. Nearest vectors 【极角排序atan2法】
- 【Educational Codeforces Round 1C】【计算几何-极角排序 atan2 long double】Nearest vectors 平面图上原点引出角度最小的两个
- Codeforces 598C. Nearest vectors【高精度几何】
- codeforces_598C. Nearest vectors(极角排序)
- Codeforces Educational Round 1 C题
- Educational Codeforces Round 1
- Educational Codeforces Round 21 C
- Educational Codeforces Round 5 C
- Educational Codeforces Round 26 C
- 【CODEFORCES】 Educational Codeforces Round 1
- --Satoshi--大数据学习日志(2017.07.19)
- Java NIO系列教程(四) Scatter/Gather
- HAWQ + MADlib 玩转数据挖掘之(四)——低秩矩阵分解实现推荐算法
- 2017.7.19-学习日志-大数据
- overridePendingTransition的简介
- Educational Codeforces Round 1-积角排序-C. Nearest vectors
- vector的实现
- GDI泄漏造成程序异常或卡死
- (斯特林数)Examining the Rooms--HDOJ
- Spring通过工厂方法配置bean
- FFMPEG学习【libavutil】:数据结构(二)
- C语言结构体课堂总结
- Python随机数的写法
- Oracle 创建表空间