zoukankan      html  css  js  c++  java
  • Gym

    题目很长,但是意思就是给你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;
    }
    View Code
  • 相关阅读:
    C++ 引用做左值
    C++ 引用本质的详解
    C++ 引用基础
    C语言错误 指针的类型错误
    C++ c++与C语言的区别(三目运算符,const修饰符)
    C++ c++与C语言的区别(struct类型的加强,函数-变量类型加强,bool类型)
    C++ c++与C语言的区别(实用性增强,register关键字增强,全局变量检测增强)
    C++ c++初识
    C语言 Linux内核链表(企业级链表)
    C语言 结构体中属性的偏移量计算
  • 原文地址:https://www.cnblogs.com/Aragaki/p/11299842.html
Copyright © 2011-2022 走看看