• POJ 1122 FDNY to the Rescue! Floyd 打印路径就行了


      题目大意:

    纽约消防部门的支援速度是值得纽约人骄傲的一件事。但是他们想要最快的支援速度,帮助他们提升支援速度他们要调度离着火点最近的一个消防站。他们要你写一个程序来维护纽约消防站的光荣传统。软件需要有的功能是,能获取着火点的地址 和 消防站的位置, 街道交叉路口, 从一个交叉路口到达另一个交叉路口的时间。 他将要计算从消防站到达着火点需要多少时间。

    给你一个具体的着火点的地址,这个软件应该找出所有消防站到达着火点的距离, 并且从小到大进行排序。以便消防员来调度人员到达救火地点。

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <cmath>
    #include <cstring>
    using namespace std;
    #define INF 0xfffffff
    #define maxn 40
    
    struct Point
    {
        int e, w;
    } dist[maxn];
    
    bool cmp(Point A,Point B)
    {
        return A.w < B.w;
    }
    int Path[maxn][maxn], G[maxn][maxn], n;
    
    void Floyd()
    {
        for(int k=1; k<=n; k++)
        {
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=n; j++)
                {
                    if(G[i][j] > G[i][k] + G[k][j] )
                    {
                        G[i][j] = G[i][k] + G[k][j];
                        Path[i][j] = Path[i][k];
                    }
                }
            }
        }
    }
    
    void PutPath(int Star,int End)
    {
        while(Star != End)
        {
            printf("	%d", Star);
            Star = Path[Star][End];
        }
        printf("	%d
    ", Star);
    }
    
    int main()
    {
        int a;
    
        cin >> n;
    
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                Path[i][j] = j;
                cin >> G[i][j];
    
                if(G[i][j] == -1)
                    G[i][j] = INF;
            }
        }
        int End, k = 0;
    
        Floyd();
    
        cin >> End;
    
        while(scanf("%d",&a) != EOF)
        {
            dist[k].w = G[a][End];
            dist[k++].e = a;
        }
    
        sort(dist, dist + k, cmp);
    
        cout << "Org	Dest	Time	Path" << endl;
    
        for(int i=0; i<k; i++)
        {
            printf("%d	%d	%d", dist[i].e, End, G[dist[i].e][End]);
    
            PutPath(dist[i].e, End);
        }
        return 0;
    }
  • 相关阅读:
    【UVA11324】 The Largest Clique (Tarjan+topsort/记忆化搜索)
    【洛谷2245】 星际导航 (最小瓶颈路)
    【UVA10816】Travel in Desert (最小瓶颈路+最短路)
    【洛谷 5002】专心OI
    炸金花【大模拟】
    【BZOJ1055】[HAOI2008]玩具取名(区间DP)
    【BZOJ1296】[SCOI2009]粉刷匠 (DP+背包)
    NOIP前的模板
    获取<考试>博文密码!o(*≧▽≦)ツ
    这是个萌新的萌新博客
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4172423.html
Copyright © 2020-2023  润新知