Educational Codeforces Round 1 C - Nearest vectors
来源:互联网 发布:cube escape 知乎 编辑:程序博客网 时间:2024/04/30 01:56
【题意】求n个从原点出发的向量中相距最近的两个的编号
【解题方法】极角排序!
【AC code】
#include <bits/stdc++.h>using namespace std;const int maxn=100010;const double PI=acos(-1);int n;struct Point{ int x,y,id; long double ang; void read(){ scanf("%d%d",&x,&y); ang=atan2(y,x); } bool operator<(const Point &p) const{ return ang<p.ang; }}a[maxn];int main(){ cin>>n; for(int i=1; i<=n; i++){ a[i].read(); a[i].id=i; } sort(a+1,a+n+1); a[n+1]=a[1]; a[n+1].ang+=2*PI; long double ang=0x3f3f3f3f; int id; for(int i=1; i<=n; i++){ long double now=a[i+1].ang-a[i].ang; if(ang>now){ ang=now; id=i; } } printf("%d %d\n",a[id].id,a[id+1].id);}
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 1C. Nearest vectors
- Educational Codeforces Round 1 C.Nearest vectors(排序)
- Educational Codeforces Round 1-积角排序-C. 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 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
- codeforces Educational Codeforces Round 16-C
- cookie共享于二级域名
- POJ 3662 Telephone Lines 电话线(二分答案+SPFA)
- iOS项目的静态代码扫描之OClint安装
- 问题:jquery中的.on() .one() .off()函数
- Light-oj 1078 (除法模拟)
- Educational Codeforces Round 1 C - Nearest vectors
- python入门神图
- android开发步步为营之108:下载断点续传
- 数据结构实验之栈三:后缀式求值
- 欢迎使用CSDN-markdown编辑器
- C#控制台 输出hello world之 在main函数下使用console.writeline
- C语言文件操作函数
- XML解析之pull解析
- Android自定义View实战---圆盘温度计