PKU 2253 类FLOYD求最小最大值

就是求所有可能路径中每段中最大长度的最小值
用了一个类似FLOYED的方法

代码如下
/**********************
Author: WHU_Victordu
Created Time: 2007-12-28
File Name: pku2253.cpp
  Description: 
   **************************/
#include <iostream>
#include <cmath>

using namespace std;

double a[202][202];
struct node
{
     double x, y;
};
node point[202];

int main()
{
     int n, t = 1,i,j,k;
     while(scanf("%d", &n) && n)
     {
         for( i = 1; i <= n; i++)
             cin >> point[i].x >> point[i].y;

         for( i = 1; i <= n; i++)
         {
             a[i][i] = 0;
             for( j = i+1; j <= n; j++)
             {
                 a[j][i] = a[i][j] = sqrt((point[i].x - point[j].x)*(point[i].x - point[j].x)
                     + (point[i].y - point[j].y)*(point[i].y - point[j].y));
             }
         }

         for(int k = 1; k <= n; k++)
             for(int i = 1; i <= n; i++)
                 for(int j = 1; j <= n; j++)
                 {
                     double m = max(a[i][k], a[k][j]);
                     if(m < a[i][j]) a[i][j] = a[j][i] = m;
                 }

         printf("Scenario #%d\n", t++);
         printf("Frog Distance = %.3f\n\n",a[1][2]);
     }
}

posted on 2007-12-28 23:56 Victordu 阅读(922) 评论(3)  编辑 收藏 引用

评论

# re: PKU 2253 类FLOYD求最小最大值 2007-12-29 13:53 winsty

不知这题可不可以用二分搞...,  回复  更多评论   

# re: PKU 2253 类FLOYD求最小最大值 2007-12-30 13:19 Victordu

maybe~效率可能会高很多 不过这个数据规模不大@winsty
  回复  更多评论   

# re: PKU 2253 类FLOYD求最小最大值 2009-01-07 12:44 fan

大牛好,为什么我用你的代码过不了Sample的第二组数据,却交上去是AC?  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

<2007年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

统计

常用链接

留言簿(5)

随笔档案(46)

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜