//注意矩形建图
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
double edge[440][440], x[440], y[440], ans, ti, t;
int tot, s, A, B, belong[440];
void init(){
memset(edge, 0, sizeof(edge));
memset(x, 0, sizeof(x));
memset(y, 0, sizeof(y));
memset(belong, 0, sizeof(belong));
ans = inf;
tot = 0;
}
void build(int num, double ti){
int n1 = tot - 2, n2 = tot - 1, n3 = tot, n4;
edge[n1][n2] = edge[n2][n1] = pow((x[n1] - x[n2]), 2) + pow((y[n1] - y[n2]), 2);
edge[n1][n3] = edge[n3][n1] = pow((x[n1] - x[n3]), 2) + pow((y[n1] - y[n3]), 2);
edge[n2][n3] = edge[n3][n2] = pow((x[n2] - x[n3]), 2) + pow((y[n2] - y[n3]), 2);
if(edge[n1][n2] + edge[n1][n3] == edge[n2][n3]) n4 = n1;
else if(edge[n1][n2] + edge[n2][n3] == edge[n1][n3]) n4 = n2;
else /*if(edge[n1][n3] + edge[n2][n3] == edge[n1][n2])*/ n4 = n3;
tot++;
if(n4 == n1){
double dx = x[n1] - x[n2];
double dy = y[n1] - y[n2];
x[tot] = x[n3] - dx;
y[tot] = y[n3] - dy;
}
else if(n4 == n2){
double dx = x[n2] - x[n1];
double dy = y[n2] - y[n1];
x[tot] = x[n3] - dx;
y[tot] = y[n3] - dy;
}
else if(n4 == n3){
double dx = x[n3] - x[n1];
double dy = y[n3] - y[n1];
x[tot] = x[n2] - dx;
y[tot] = y[n2] - dy;
}
for(int j = tot - 3; j <= tot; j++)
for(int k = tot - 3; k < j; k++)
edge[j][k] = edge[k][j] = hypot(x[j] - x[k], y[j] - y[k]) * ti;
//edge[j][k] = edge[k][j] = sqrt(pow(x[j]-x[k], 2) + pow(y[j]-y[k], 2)) * ti;
belong[tot] = num;
}
void floyd(){
for(int k = 1; k <= tot; k++)
for(int i = 1; i <= tot; i++)
for(int j = 1; j <= tot; j++)
edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j]);
for(int i = 1; i <= tot; i++)
for(int j = 1; j <= tot; j++)
if(belong[i] == A && belong[j] == B)
ans = min(edge[i][j], ans);
}
int main(){
int n;
cin >> n;
while(n--){
init();
cin >> s >> t >> A >> B;
for(int i = 1; i <= s; i++){
for(int j = 1; j <= 3; j++){
tot++;//切记输入时不可同时用++
cin >> x[tot] >> y[tot];
belong[tot] = i;
}
cin >> ti;
build(i, ti);
}
for(int i = 1; i <= tot; i++)
for(int j = 1; j < i; j++)
if(belong[i] != belong[j])
edge[i][j] = edge[j][i] = hypot(x[i] - x[j], y[i] - y[j]) * t;
floyd();
/*for(int i = 1; i <= tot; i++)
for(int j = 1; j <= tot; j++)
printf("%0.1lf ", edge[i][j]);*/
printf("%0.1lf\n", ans);
}
return 0;
}
CODEVS 1041 Car的旅行路线
最新推荐文章于 2024-07-02 15:26:42 发布