小编And*_*Lay的帖子

求连接2N个点的线段的最小总长度

我试图通过暴力破解这个问题,但是当给定 7 (即 2*7 点)时,它似乎运行得很慢。

注意:我只需要运行到最大2*8点

问题陈述:

给定 2d 平面上的 2*N 个点,将它们成对连接以形成 N 条线段。最小化所有线段的总长度。

例子:

输入:5 10 10 20 10 5 5 1 1 120 3 6 6 50 60 3 24 6 9 0 0

输出:118.4

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

class point{
public:
    double x, y;
};

double getLength(point a, point b){
    return hypot((a.x - b.x), (a.y - b.y));
}

static double mini = INT_MAX;

void solve(vector <point> vec, double …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm optimization performance brute-force

5
推荐指数
1
解决办法
264
查看次数

标签 统计

algorithm ×1

brute-force ×1

c++ ×1

optimization ×1

performance ×1