题目很长,但是意思就是给你n,A,B,C,D
n表示有n个城市 A是飞机的重量 B是一个常数表示转机代价 C是单位燃油的价格 D是一个常数
假设一个点到另外一个点的距离为整数L 起飞前的油量为f 则在这途中每飞行一单位距离 就花费(f+A)/D的燃油
#include <bits/stdc++.h> typedef long long ll; typedef long double lb; using namespace std; const int MAXN=205,MAXM=80005; int to[MAXM << 1], nxt[MAXM << 1], Head[MAXN], ed = 1; lb cost[MAXM << 1]; int n; inline void addedge(int u, int v, lb c) { to[++ed] = v; nxt[ed] = Head[u]; Head[u] = ed; cost[ed] = c; } struct HeapNode { int u; lb d; bool operator < (const HeapNode& rhs) const { return d > rhs.d; } } zz; lb mindist[MAXN]; bool vis[MAXN]; priority_queue<HeapNode> que; void Hijkstra(int s) { for (int i = 0; i <= n; i++) { mindist[i] = 4000000000000000000.0; } mindist[s] = 0.0; memset(vis, 0, sizeof(vis)); zz.d = 0, zz.u = s; que.push(zz); while (!que.empty()) { HeapNode x = que.top(); que.pop(); int u = x.u; if (vis[u] || mindist[u] != x.d) { continue; } vis[u] = true; for (int v, i = Head[u]; i; i = nxt[i]) { v = to[i]; if (mindist[v] > mindist[u] + cost[i]) { mindist[v] = mindist[u] + cost[i]; //p[v]=u; zz.d = mindist[v], zz.u = v; que.push(zz); } } } } void init(int x) { ed = 1; for (int i = 1; i <= x; i++) { Head[i] = 0; } } struct node { ll x, y; } P[MAXN]; int main() { int TC; scanf("%d", &TC); while (TC--) { ll A, B, C, D; scanf("%d %lld %lld %lld %lld", &n, &A, &B, &C, &D); init(n); for (int i = 1; i <= n; i++) { scanf("%lld %lld", &P[i].x, &P[i].y); } for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { ll ax = abs(P[i].x - P[j].x); ll ay = abs(P[i].y - P[j].y); ll dis = ax * ax + ay * ay; dis = ceil(sqrt(dis)); lb c = (pow((lb)D / (D - 1.0), dis) - 1.0) * A * C + B; addedge(i,j,c),addedge(j,i,c); } } Hijkstra(1); printf("%.10Lf ", mindist[n]); } return 0; }