POJ 2253 Frogger floyd算法
题目:click here
题意:
给出两只青蛙的坐标A、B,和其他的n-2个坐标,任意两坐标间是双向连通的。显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中又有一个最大距离。现在要求求出所有通路的最大距离,并把这些最大距离作比较,把最小的一个最大距离作为青蛙的最小跳远距离。
分析:
最小化最大值--------
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#define power(a) ((a)*(a))
using namespace std;
const int INF = 1e9+;
const int M = ; struct node { double x, y; } point[M]; // 点的坐标
int n, tcase;
double cost[M][M]; // 邻接矩阵存图
double dis( node a, node b ) { // 距离
return sqrt( power(a.x-b.x) + power(a.y-b.y) );
} void floyd() { // 弗洛伊德算法
for( int k=; k<=n; k++ )
for( int i=; i<=n; i++ )
for( int j=; j<=n; j++ )
cost[i][j] = min( cost[i][j], max(cost[i][k],cost[k][j]) );
} void solve() {
for( int i=; i<=n; i++ )
scanf("%lf%lf", &point[i].x, &point[i].y );
for( int i=; i<=n; i++ ) {
cost[i][i] = ;
for( int j=i+; j<=n; j++ ) {
double d = dis( point[i], point[j] );
cost[i][j] = d; // 建立无向图
cost[j][i] = d;
}
}
floyd();
printf("Scenario #%d\n", tcase++);
printf("Frog Distance = %.3f\n\n", cost[][] );
}
int main() {
tcase = ;
while( ~scanf("%d", &n ) && n ) {
solve();
}
return ;
}
POJ 2253 Frogger floyd算法的更多相关文章
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
随机推荐
- Windows Azure 社区新闻综述(#70 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章.视频和博客文章 · 如何选择 No ...
- iPhone/iTouch免99美刀真机调试
本文经本人验证,攻略来源于网上,由于多次转载原始出处不可靠,故无法对原作者进行链接引用,抱歉. 本文仅为记录流程,以备日后查询.本文版权所无,欢迎转载和拍砖. 测试环境: XCode 4.0.2 + ...
- poj2350
#include <stdio.h> #include <stdlib.h> int main() { ],tim,i; scanf("%d",&n ...
- android 内存优化
OOM 内存泄漏引起很多问题: 1:节目卡顿.反应慢(高内存使用情况JVM 虚拟机的频繁离职GC) 2:消失 3:直接崩溃 ANDROID 内存面临的问题 1: 有限的堆内存,原始仅仅有16M 2:内 ...
- MySQL学习笔记(2)
打开数据库 USE db_name; SELECT DATABASE();查看当前所选中的数据库 创建数据表 CREATA TABLE [IF NOT EXISTS] table_name ( col ...
- C# 轮循回调
class Program { static void Main(string[] args) { Func<int> func = new Func<int>(GetInt) ...
- wing 5.0 注册机
输入License id 进入下一页获得request key ,输入request key 后点击生成,即可生成激活码,亲测可用 下载链接 密码:adwj
- Linux学习之守护进程详解
Linux系统守护进程详解 ---转自:http://yuanbin.blog ...
- Java基础之"=="和 和 equals 方法的区别
一."=="操作符 ==操作符专门用来比较两个变量的值是否相等,也就是用于比较变量所对应的内存中所存储的数值是否相同,要比较两个基本类型的数据或两个引用变量是否相等,只能用==操作 ...
- javascript小练习—点击将DIV变成红色(通过for循环遍历)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...