zoukankan      html  css  js  c++  java
  • Frogger POJ 2253

    http://poj.org/problem?id=2253

    题意:有一只青蛙A想要跳到另一只青蛙B处, 由于青蛙A的跳跃幅度没有那么大, 所以它需要借助它周边的一些石头从而到达青蛙B处。问你在众多可供选择的道路中,哪条道路中跳跃的最大值要比其他道路中的最大值小。(也就是求它的跳跃幅度至少要为多少)

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<queue>
    using namespace std;
    typedef long long LL;
    #define oo 0x3f3f3f3f
    #define maxn 500
    double maps[maxn][maxn], dist[maxn];
    int v[maxn];
    int n;
    
    struct node
    {
        int x, y;
    }A[maxn];
    
    double F(int i, int j)
    {
        return (sqrt(pow((double)A[i].x-A[j].x, 2)+pow((double)A[i].y-A[j].y, 2)));
    }
    
    double Dij()
    {
        memset(v, 0, sizeof(v));
        for(int i=1; i<=n; i++)
        dist[i] = maps[1][i];
    
        dist[1] = 0;
        v[1] = 1;
    
        for(int i=1; i<n; i++)
        {
            int index;
            double mins = 10000000;
            for(int j=1; j<=n; j++)
            {
                if(!v[j] && dist[j] < mins)
                {
                    index = j;
                    mins = dist[j];
                }
            }
    
            v[index] = 1;
    
            for(int j=1; j<=n; j++)
            {
                if(!v[j] && dist[j]>max(mins, maps[index][j]))
                {
                  dist[j]=max(mins, maps[index][j]);
                }
            }
        }
        return dist[2];
    }
    
    int main()
    {
         int cnt = 1;
         while(scanf("%d", &n), n)
         {
             for(int i=1; i<=n; i++)
                scanf("%d %d", &A[i].x, &A[i].y);
    
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<i; j++)
                {
                    maps[i][j] = maps[j][i] = F(i, j);
                }
                maps[i][i] = 0;
            }
    
           double ans = Dij();
           printf("Scenario #%d
    ", cnt++);
           printf("Frog Distance = %.3f
    
    ", ans);
    
         }
        return 0;
    }
    View Code
    #include<algorithm>
    #include<queue>
    #include<stdio.h>
    #include<string.h>
    #include<vector>
    #include<math.h>
    using namespace std;
    
    const int maxn = 205;
    const int oo = 0xfffffff;
    
    struct point
    {
        double x, y;
    } p[maxn];
    struct node
    {
        int y;
        double len;
        node(int y, double len):y(y), len(len) {}
    };
    vector<node> G[maxn];
    double v[maxn];
    
    //求两点间的距离
    double Len(point a, point b)
    {
        return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    }
    void Spfa()
    {
        queue<int> Q;
        Q.push(1);
    
        while(Q.size())
        {
            int s = Q.front();
            Q.pop();
            int len = G[s].size();
    
            for(int i=0; i<len; i++)
            {
                node q = G[s][i];
    
                if(v[s] < v[q.y] && q.len < v[q.y])
                {
                    v[q.y] = max(v[s], q.len);//要选取一条路上的最大的那条边
                    Q.push(q.y);
                }
            }
        }
    }
    
    int main()
    {
        int N, t=1;
    
        while(scanf("%d", &N), N)
        {
            int i, j;
    
            for(i=1; i<=N; i++)
                scanf("%lf%lf", &p[i].x, &p[i].y);
    
            for(i=1; i<=N; i++)
                for(j=1; j<=N; j++)
                {
                    if(i == j)
                        continue;
    
                    double len = Len(p[i], p[j]);
                    G[i].push_back(node(j, len));
                }
    
            for(i=1; i<=N; i++)
                v[i] = oo;
            v[1] = 0;
    
            Spfa();
    
            if(t != 1)printf("
    ");
            printf("Scenario #%d
    ", t++);
            printf("Frog Distance = %.3f
    ", v[2]);
    
            for(i=1; i<=N; i++)
                G[i].clear();
        }
    
        return 0;
    View Code
  • 相关阅读:
    [转]django自定义表单提交
    [django/mysql] 使用distinct在mysql中查询多条不重复记录值的解决办法
    [Django]下拉表单与模型查询
    [Django]模型提高部分--聚合(group by)和条件表达式+数据库函数
    [Django]模型学习记录篇--基础
    [Django]数据批量导入
    怎么让自己的本地php网站让别人访问到
    HTML Marquee跑马灯
    marquee标签详解
    apache的虚拟域名rewrite配置以及.htaccess的使用。
  • 原文地址:https://www.cnblogs.com/daydayupacm/p/5685535.html
Copyright © 2011-2022 走看看