问题描述
/*
* 给定一些 points 和一个 origin, 从points中找出k个离origin最近的点,按照距离从小到大返回
* 如果有两个点有相同距离,按照x值进行排序,如果x值相等,按照y值进行排序
*
* 如果是静态数据,数据量不是特别多的话,直接做个排序就可以了
* 如果是动态数据的话,维护一个最小堆
*/
代码
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
typedef std::pair<int, int> P;
struct LessCmp {
bool reverse;
LessCmp(bool reverse = false): reverse(reverse) {}
bool operator()(P &a, P &b) {
bool res;
double dis1 = a.first * a.first + a.second * a.second,