当前位置: 首页>>代码示例>>C++>>正文


C++ KDTree::Solve方法代码示例

本文整理汇总了C++中KDTree::Solve方法的典型用法代码示例。如果您正苦于以下问题:C++ KDTree::Solve方法的具体用法?C++ KDTree::Solve怎么用?C++ KDTree::Solve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KDTree的用法示例。


在下文中一共展示了KDTree::Solve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
#ifndef ONLINE_JUDGE
    // GenBig();
    // freopen("big.txt", "r", stdin);
    // freopen("input.txt", "r", stdin);
    GenInt();
    freopen("int.txt", "r", stdin);
#endif

#ifndef __linux__
    SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
#endif

    int m;
    scanf("%d", &m);

    int size = m + 8;

    long double* xcd = (long double*)_mm_malloc(sizeof(long double)*size, 32);
    long double* ycd = (long double*)_mm_malloc(sizeof(long double)*size, 32);
    long double mx = 1e-5;
    for (int i = 0; i < m; ++i)
    {
        scanf("%Lf%Lf", &xcd[i], &ycd[i]);
        mx = Max(mx, abs(xcd[i]));
        mx = Max(mx, abs(ycd[i]));
    }

    TIntVector indices(m);
    for (int i = 0; i < m; ++i)
    {
        indices[i] = i;
    }

    for (int i = 0; i < m; ++i)
    {
        swap(indices[i], indices[i + (rand() % (m - i))]);
    }

    TDoubles xc(m);
    TDoubles yc(m);
    for (int i = 0; i < m; ++i)
    {
        xc[i] = xcd[indices[i]] / mx;
        yc[i] = ycd[indices[i]] / mx;
    }

    KDTree* kdTree = new KDTree(0, xc, yc, indices);
    // CircleTree* cTree = new CircleTree(0, xc, yc, indices);

    int n;
    scanf("%d", &n);
    vector<int> result;
    result.reserve(m);
    vector<int> result2;
    result2.reserve(m);
    for (int i = 0; i < n; ++i)
    {
        long double xd, yd;
        scanf("%Lf%Lf", &xd, &yd);

        double x = xd/mx;
        double y = yd/mx;
        TVector x2;
        x2.v = _mm_set1_pd(x);
        TVector y2;
        y2.v = _mm_set1_pd(y);

        result.clear();
        double minDist = 1e100;
        TVector minMax;
        minMax.v = _mm_set1_pd(minDist);
        double minMin = minDist;
        kdTree->Solve(x, y, x2, y2, &minDist, &minMax, &minMin, &result);
        // cTree->Solve(x, y, x2, y2, &minDist, &minMax, &minMin, &result);

        if (result.size() < 5)
        {
            result2.clear();
            long double mind = 1e15;
            long double mindMin = mind;
            long double mindMax = mind;
            for (auto realindex : result)
            {
                long double dist = Sqr(xd - xcd[realindex]) + Sqr(yd - ycd[realindex]);
                static const long double LDEPS = 1e-10;
                if (dist < mindMin)
                {
                    mind = dist;
                    mindMin = dist - LDEPS;
                    mindMax = dist + LDEPS;
                    result2.clear();
                }
                if (dist <= mindMax)
                {
                    result2.push_back(realindex);
                }
            }
        }
//.........这里部分代码省略.........
开发者ID:evilmucedin,项目名称:timus,代码行数:101,代码来源:1369.cpp


注:本文中的KDTree::Solve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。