本地A,洛谷CE求调
查看原帖
本地A,洛谷CE求调
1251404
Alan1234567890楼主2024/5/1 14:56
#include <iostream>
#include <cmath>
using namespace std;
int n, f[20];
double x[20], y[20];
double ans = 1234567898.0;
double compute(int a, int b){
	return sqrt((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]));
}
void dfs(int d, double len, int step){
	if (len > ans)	return;
	if (step == n) {
		ans = len;
		return;
	}
	for (int i = 1; i <= n; i++){
		if (!f[i]) {
			f[i] = 1;
			dfs(i, len + compute(d, i), step + 1);
			f[i] = 0;
		}
	}
}
int main(){
	scanf_s("%d", &n);
	x[0] = 0;
	y[0] = 0;
	for (int i = 1; i <= n; i++)
		scanf_s("%lf%lf", &x[i], &y[i]);
	dfs(0, 0.0, 0);
	printf("%.2lf", ans);
	return 0;
}
2024/5/1 14:56
加载中...