• POJ-2253-Frogger


    链接:https://vjudge.net/problem/POJ-2253

    题意:

    给n个点,求1->2的路径的每段路中的最大值的最短路。

    思路:

    刚开始看不懂题。看了题解后看明白的。

    直接Dijkstra算法,Dis数组保存到每点路径中的路段的最大值。

    代码:

    #include <iostream>
    #include <stack>
    #include <memory.h>
    #include <string>
    #include <algorithm>
    #include <math.h>
    #include <iomanip>
    using namespace std;
    const int MAXN = 200+10;
    double Map[MAXN][MAXN];
    double Dis[MAXN];
    int Vis[MAXN];
    int n;
    
    struct Node
    {
        double _x;
        double _y;
    }node[MAXN];
    
    double get_Len(Node a,Node b)
    {
        return sqrt((a._x-b._x)*(a._x-b._x) + (a._y-b._y)*(a._y-b._y));
    }
    
    double Dijkstra()
    {
        memset(Dis,0, sizeof(Dis));
        memset(Vis,0, sizeof(Vis));
        for (int i = 2;i<=n;i++)
        {
            Dis[i] = Map[1][i];
        }
        Vis[1] = 1;
        for (int i = 1;i<=n;i++)
        {
            int w;
            double small = 9999999.0;
            for (int j = 1; j <= n; j++)
            {
                if (Vis[j] == 0 && small > Dis[j])
                {
                    w = j;
                    small = Dis[j];
                }
            }
    
            Vis[w] = 1;
    
            if (w == 2)
                return small;
    
            for (int j = 1; j <= n; j++)
            {
                if (Vis[j] == 0)
                {
                    //double now = max(small,Map[w][j]);
                    //if (now < Dis[j])
                        //Dis[j] = now;
                    Dis[j] = min(Dis[j], max(small, Map[w][j]));
                }
            }
        }
    }
    
    int main()
    {
        int cnt = 0;
        while (cin >> n && n)
        {
            for (int i = 1;i<=n;i++)
            {
                cin >> node[i]._x;
                cin >> node[i]._y;
            }
            for (int i = 1;i<=n;i++)
                for (int j = 1;j<=n;j++)
                    Map[i][j] = Map[j][i] = get_Len(node[i],node[j]);
    
            double v = Dijkstra();
            if (cnt != 0)
                printf("
    ");
            printf("Scenario #%d
    Frog Distance = %.3f
    ",++cnt,v);
        }
    }
    

      

  • 相关阅读:
    在HQL里使用set方式设置的变量
    Nuxt.js 使用vue-social-share.js 插件 分享功能实践
    渗透测试被动信息搜集工具v0.1
    burp工具tips集合
    Go语言之数据类型(二)
    Go语言之数据类型(一)
    Go语言之变量
    Go语言快速入门
    Go语言环境搭建
    [SSH]基础知识——SSH、对称加密、非对称加密、公钥、私钥、中间人攻击
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10272219.html
Copyright © 2020-2023  润新知