分治--最近点对问题

在这里插入图片描述
一维:
排序后过一遍后-前即可

#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int a[5] = {2,3,1,4,5};
    sort(a, a+5);
    int minValue = a[1] - a[0];
    for (int i = 2; i < 5; ++i) {
        int temp = a[i] - a[i-1];
        minValue = min(minValue, temp);
    }
    cout << minValue << endl;
    return 0;
}

二维:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

发布了133 篇原创文章 · 获赞 11 · 访问量 2886

猜你喜欢

转载自blog.csdn.net/qq_43410618/article/details/104883955