#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
int n, s, tf, a, b, i, j, k, count = 1, count1 = 0, count2 = 0; //tf means the prize of flying, tr means the prize of walking, count starts with "1", which means the position of all points, count1 starts with "0", which means the lines' number among every points, count2 starts with "0", which works as the mid worker.
double px[105], py[105], tr[105], op[500], top[105], map[405][405], max1, max2, ans = 999999999;
//inputting part
cin >> n;
for(int num = 1; num <= n; num++)
{
memset(map, 999999999, sizeof(map));
cin >> s >> tf >> a >> b;
for(i = 0; i < s; i++)
{
for(j = 1; j <= 3; j++)
{
cin >> px[count - 1] >> py[count - 1];
count++;
}
op[count1] = sqrt(fabs(px[count - 4] - px[count - 3]) * fabs(px[count - 4] - px[count - 3]) + fabs(py[count - 4] - py[count - 3]) * fabs(py[count - 4] - py[count - 3]));
count1++;
op[count1] = sqrt(fabs(px[count - 4] - px[count - 2]) * fabs(px[count - 4] - px[count - 2]) + fabs(py[count - 4] - py[count - 2]) * fabs(py[count - 4] - py[count - 2]));
count1++;
op[count1] = sqrt(fabs(px[count - 3] - px[count - 2]) * fabs(px[count - 3] - px[count - 2]) + fabs(py[count - 3] - py[count - 2]) * fabs(py[count - 3] - py[count - 2]));
count1++;
max1 = max(op[count1 - 3], op[count1 - 2]);
max2 = max(max1, op[count1 - 1]);
top[count2] = max2;
if(ceil(top[count2]) == ceil(sqrt(fabs(px[count - 4] - px[count - 3]) * fabs(px[count - 4] - px[count - 3]) + fabs(py[count - 4] - py[count - 3]) * fabs(py[count - 4] - py[count - 3]))))
{
px[count - 1] = px[count - 4] + px[count - 3] - px[count - 2];
py[count - 1] = py[count - 4] + py[count - 3] - py[count - 2];
}
if(ceil(top[count2]) == ceil(sqrt(fabs(px[count - 4] - px[count - 2]) * fabs(px[count - 4] - px[count - 2]) + fabs(py[count - 4] - py[count - 2]) * fabs(py[count - 4] - py[count - 2]))))
{
px[count - 1] = px[count - 4] + px[count - 2] - px[count - 3];
py[count - 1] = py[count - 4] + py[count - 2] - py[count - 3];
}
if(ceil(top[count2]) == ceil(sqrt(fabs(px[count - 3] - px[count - 2]) * fabs(px[count - 3] - px[count - 2]) + fabs(py[count - 3] - py[count - 2]) * fabs(py[count - 3] - py[count - 2]))))
{
px[count - 1] = px[count - 3] + px[count - 2] - px[count - 4];
py[count - 1] = py[count - 3] + py[count - 2] - py[count - 4];
}
count2++;
count++;
cin >> tr[i];
}
//map building part
for(i = 0; i < count - 1; i++) // A potential problem, but who cares?
{
for(j = 0; j < count - 1; j++)
{
if(i / 4 + 1 != j / 4 + 1) //To see whether these 2 points are in a same city.
{
map[i][j] = tf * sqrt(fabs(px[i] - px[j]) * fabs(px[i] - px[j]) + fabs(py[i] - py[j]) * fabs(py[i] - py[j]));
}
else //They are in a same city.
{
map[i][j] = tr[(i + 1) / 4] * sqrt(fabs(px[i] - px[j]) * fabs(px[i] - px[j]) + fabs(py[i] - py[j]) * fabs(py[i] - py[j]));
}
}
}
//Calculating part (Floyd- Warshall et etc.)
for(k = 0; k < count - 1; k++)
{
for(i = 0; i < count - 1; i++)
{
for(j = 0; j < count - 1; j++)
{
if(map[i][j] > map[i][k] + map[k][j])
{
map[i][j] = map[i][k] + map[k][j];
}
}
}
}
//It's just an adjustment.
for(i = 0; i < s * 4; i++)
{
for(j = 0; j < s * 4; j++)
{
cout << map[i][j] << " ";
}
cout << "%%%%%%%" << endl;
}
for(i = a * 4 - 1; i >= a * 4 - 4; i--)
{
for(j = b * 4 - 1; j >= b * 4 - 4; j--)
{
if(map[i][j] < ans)
{
ans = map[i][j];
}
}
}
printf("%.1lf",ans);
}
return 0;
}
顺便附上数据: IN: 1 10 10 1 2 27 27 194 105 194 27 10 366 290 381 290 366 305 10 80 158 196 245 196 158 1 289 154 358 154 358 86 2 17 284 84 350 84 284 1 175 289 292 289 175 362 3 450 371 420 371 420 32 2 241 29 270 29 270 43 4 251 182 347 270 251 270 5 347 341 410 341 347 369 1 OUT: 1885.0