⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2145.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/*  This Code is Submitted by wywcgs for Problem 2145 on 2006-01-11 at 16:56:20 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 64;
const double INF = 2e10;

class Point {
public:
	double x, y;
	void make();
	double dis(const Point&) const;
};
void Point::make() {
	scanf("%lf %lf", &x, &y);
}
double Point::dis(const Point& p) const {
	return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}

int main()
{
	double d[MAX][MAX], sum[MAX][MAX], b[MAX];
	Point p[MAX];
	int i, j, n, m;
	
	while(scanf("%d", &n) != EOF) {
		for(i = 0; i < n; i++) {
			p[i].make();
			for(j = 0; j <= i; j++) d[i][j] = d[j][i] = p[i].dis(p[j]);
		}
		memset(sum, 0, sizeof(sum));
		for(i = 1; i < n; i++)
			for(j = 0; (m = j+i) < n; j++)
				sum[j][m] = sum[j][m-1] + d[m-1][m];
		b[1] = 2 * d[0][1];
		for(i = 2; i < n; i++) {
			b[i] = INF;
			for(j = 0; j < i-1; j++)
				b[i] = min(b[i], b[j+1]-d[j][j+1]+d[j][i]+sum[j+1][i]);
		}
		printf("%.2lf\n", b[n-1]);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -