一看数据就是floyed(毕竟年代久远),然而建图不是那么好贱好建,只知道三个机场,需要判断斜边来求第4个机场坐标。
往后一些麻烦的建图。
最后floyed就好。
——代码
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int n, s, a, b; ][], y[][], T[]; ][], ans; inline int square(int ax) { return ax * ax; } inline int dis(int ax, int ay, int bx, int by) { return square(ax - bx) + square(ay - by); } int main() { int i, j, k; scanf("%d", &n); while(n--) { scanf("%d %d %d %d", &s, &t, &a, &b); ; i < * s; i++) ; j < * s; j++) map[i][j] = ; ans = ; ; i < s; i++) { scanf(], &y[i][], &x[i][], &y[i][], &x[i][], &y[i][], &T[i]); ], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][]) && dis(x[i][], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][])) { x[i][] = x[i][] + x[i][] - x[i][]; y[i][] = y[i][] + y[i][] - y[i][]; } ], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][]) && dis(x[i][], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][])) { x[i][] = x[i][] + x[i][] - x[i][]; y[i][] = y[i][] + y[i][] - y[i][]; } ], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][]) && dis(x[i][], y[i][], x[i][], y[i][]) > dis(x[i][], y[i][], x[i][], y[i][])) { x[i][] = x[i][] + x[i][] - x[i][]; y[i][] = y[i][] + y[i][] - y[i][]; } map[ * i][ * i + ] = map[ * i + ][ * i] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; map[ * i][ * i + ] = map[ * i + ][ * i] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; map[ * i][ * i + ] = map[ * i + ][ * i] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; map[ * i + ][ * i + ] = map[ * i + ][ * i + ] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; map[ * i + ][ * i + ] = map[ * i + ][ * i + ] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; map[ * i + ][ * i + ] = map[ * i + ][ * i + ] = sqrt(dis(x[i][], y[i][], x[i][], y[i][])) * T[i]; ; j < * i; j++) * i; k < * i + ; k++) map[k][j] = map[j][k] = sqrt(dis(x[j / ][j % + ], y[j / ][j % + ], x[k / ][k % + ], y[k / ][k % + ])) * t; } ; i < * s; i++) map[i][i] = ; ; k < * s; k++) ; i < * s; i++) ; j < * s; j++) map[i][j] = min(map[i][j], map[i][k] + map[k][j]); * a - ; i < * a; i++) * b - ; j < * b; j++) ans = min(ans, map[i][j]); printf("%.1f\n", ans); } ; }