到底为什么不对啊啊啊(解决v你30)
查看原帖
到底为什么不对啊啊啊(解决v你30)
757715
Rt__楼主2024/11/19 22:22
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double

inline ll read(){
	ll res = 0, f = 1;
	char c = getchar();
	while(c > '9' || c < '0'){
		if(c == '-')f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9'){
		res = res * 10 + c - '0';
		c = getchar();
	}
	return res * f;
}

const int N = 1010;

struct ii {
	double x, y;
	int i;
}poi[N], tree[N];

double f[N][N][2];
unordered_map<ll, ll>ma;

double d(int x, int y){
	return sqrt(pow(tree[x]. x - tree[y]. x, 2) + pow(tree[x]. y - tree[y]. y, 2));
}

int ans[N];

signed main(){
	ll n = read(), nn = n;
	ll k, sta = 0;
	double minn = 1e10;
	for(int i = 1; i <= n; i ++){
		cin >> poi[i]. x >> poi[i]. y;
		int ii = i - 1;
		if(poi[i]. y < minn){
			minn = poi[i]. y;
			sta = i;
		}
		poi[i]. i = i;
	}
	double maxx = -1e10;
	for(int i = 1; i <= n; i ++){
		tree[i] = poi[sta];
		if(tree[i]. y > maxx){
			k = i;
			maxx = tree[i]. y;
		}
		sta --;
		if(sta == 0)sta = n;
	}
	// for(int i = 1; i <= n; i ++)cout << tree[i]. x << ' ' << tree[i]. y << ' ' << tree[i]. i << endl;
	for(int i = 1; i <= n; i ++)ma[i] = tree[i]. i;
	for(int l = k; l >= 1; l --){
		for(int r = k; r <= n; r ++){
			f[l][r][0] = f[l][r][1] = 1e10;
		}
	}
	f[k][k][1] = f[k][k][0] = 0;
	for(int i = k + 1; i <= n; i ++){
		f[k][i][1] = f[k][i - 1][1] + d(i - 1, i);
	}
	for(int i = k - 1; i >= 1; i --){
		f[i][k][0] = f[i + 1][k][0] + d(i, i + 1);
	}
	for(int l = k - 1; l >= 1; l --){
		for(int r = k + 1; r <= n; r ++){
			f[l][r][0] = min(f[l + 1][r][0] + d(l, l + 1), f[l + 1][r][1] + d(l, r));
			f[l][r][1] = min(f[l][r - 1][1] + d(r, r - 1), f[l][r - 1][0] + d(l, r));
		}
	}
	// cout << min(f[1][n][0], f[1][n][1]) << endl;
	int l = 1, r = n;
	bool op;
	if(f[1][n][0] < f[1][n][1]){
		op = 0;
	}
	else{
		op = 1;
	}
	while(!(l == k && r == k)){
		if(op){
			if(abs(f[l][r - 1][0] + d(l, r) - f[l][r][op]) <= 1e-10){
				op = 0;
			}
			else{
				op = 1;
			}
			ans[nn --] = r;
			r --;
		}
		else{
			if(abs(f[l + 1][r][1] + d(l, r) - f[l][r][op]) <= 1e-10){
				op = 1;
			}
			else{
				op = 0;
			}
			ans[nn --] = l;
			l ++;
		}
	}
	ans[1] = l;
	for(int i = 1; i <= n; i ++){
		cout << ma[ans[i]] << ' ';
	}
	return 0;
}
2024/11/19 22:22
加载中...