zoukankan      html  css  js  c++  java
  • combination_m_n

    def combination_2_n(l):
        n, r = len(l), []
        for i in range(0, n, 1):
            s = i + 1
            for ii in range(s, n, 1):
                r.append([l[i], l[ii]])
        return r
    
    # l1, l2 = [23, 123], [24, 124]
    def rad(d):
        return d * np.pi / 180.0
    
    
    def compute_diff(l1, l2):
        lat1, lng1 = l1
        lat2, lng2 = l2
        radLat1, radLat2 = rad(lat1), rad(lat2)
        a = radLat1 - radLat2
        b = rad(lng1) - rad(lng2)
        inner_ = math.sqrt(math.pow(math.sin(a / 2), 2) +
                           math.cos(radLat1) * math.cos(radLat2) * math.pow(math.sin(b / 2), 2))
        s = 2 * math.asin(inner_)
        s = s * 6378.137
        s = math.ceil(s * 10000) / 10000;
        return s
    
    
    # 0-设置2组经纬度距离阈值(初始值:100米);
    # 1-如果只有一组组经纬度,则直接接受;基于经纬度条数的分布数据,认为“在保证距离阈值的情况下,
    # 取距离(并列)最近的2点的经纬度的算数平均数”是可行的;
    # latlon_l = [[142, 343], [12, 6557], [3, 666], [434, 33], [142, 6557]]
    
    def compute_macwithres_nominal_latlon(latlon_l, point_dis_threshold=500):
        n, r = len(latlon_l), {}
        if n == 1:
            return {0: latlon_l[0]}
        elif n > 1:
            c_pair = combination_2_n(latlon_l)
            for i in c_pair:
                dis = compute_diff(i[0], i[1])
                if dis > point_dis_threshold:
                    continue
                if dis not in r:
                    r[dis] = []
                r[dis].append(i)
            if r == {}:
                return {}
            else:
                min = sorted(r, reverse=False)[0]
                return {min: r[min][0]}
    
  • 相关阅读:
    BZOJ 3744 Gty的妹子序列
    BZOJ 3872 Ant colony
    BZOJ 1087 互不侵犯
    BZOJ 1070 修车
    BZOJ 2654 tree
    BZOJ 3243 向量内积
    1003 NOIP 模拟赛Day2 城市建设
    CF865D Buy Low Sell High
    CF444A DZY Loves Physics
    Luogu 4310 绝世好题
  • 原文地址:https://www.cnblogs.com/rsapaper/p/7700270.html
Copyright © 2011-2022 走看看