zoukankan      html  css  js  c++  java
  • poj2253青蛙跳跃

    1.floyd。

    一个点到另一个点的最大距离,为所有路径最大距离的最小值(二分)。

    2.答案输出。%.3lf,%.3f,遇到精度问题,要多尝试。

    **********************************************

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    const int maxn = 500;

    struct Node
    {
        int x,y;
    }a[maxn];

    int n;
    double f[maxn][maxn];

    double cal(int i,int j)
    {
        double t1=1.0*(a[i].x-a[j].x)*(a[i].x-a[j].x);
        double t2=1.0*(a[i].y-a[j].y)*(a[i].y-a[j].y);
        double ret=sqrt(t1+t2);
        return ret;
    }

    void floyd()
    {
        for(int k = 1; k <= n; k++)
            for(int i = 1; i <= n; i++)
                for(int j = 1; j <= n; j++)
                {
                    double tmp=max(f[i][k],f[k][j]);
                    if(tmp<f[i][j])f[i][j]=tmp;
                }
    }

    int main()
    {
        //freopen("in.txt","r",stdin);
        int cas=0;
        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 <= n; j++)
                    f[i][j]=cal(i,j);
            floyd();
            printf("Scenario #%d ",++cas);
            printf("Frog Distance = %.3f ",f[1][2]);
        }
        return 0;
    }

    **********************************************

  • 相关阅读:
    如何提高工作效率,重复利用时间
    好记性不如烂笔头
    如何应对面试中关于“测试框架”的问题
    通宵修复BUG的思考
    工作方法的思考
    别认为那是一件简单的事情
    开发人员需要熟悉缺陷管理办法
    不了解系统功能的思考
    如何布置任务
    事事有回音
  • 原文地址:https://www.cnblogs.com/MobileRobot/p/3774095.html
Copyright © 2011-2022 走看看