poj 2253 Frogger dijkstra算法实现
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 21653 | Accepted: 7042 |
Description
by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output
after each test case, even after the last one.
Sample Input
2
0 0
3 4 3
17 4
19 4
18 5 0
Sample Output
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
题目大意就是说一个青蛙想从一个石头跳到另一个石头上,这两个石头之间有很多其他的石头,所以青蛙有很多路径可以选择,题目要我们求出跳跃范围最少多远,青蛙才能找到一条跳过去的路,很明显,这个距离必须是这条路径上最长的。
使用Dijkstra算法,虽然这个算法是求最短路径的,而这个题目跟最短路径没有半毛钱关系,但是我们只需要把Dijkstra算法中松弛的条件改一下,就可以了,原来的dij算法中只有当前距离小于已经记录的距离的时候,会执行松弛操作,现在把这个距离改成从起点到当前点的最短跳跃距离,那么当这个最短跳跃距离变小的时候,就松弛一下
#include<stdio.h>
#include<math.h>
#include<string.h>
int n, i = 1;
double map[202][2];
double dis[202][202];
double d[202];
void dij()
{
bool flag[202] = {0};
int j, k;
int curr = 1;
for(j = 1; j <= n; j++)
{
d[j] = 0x7fffffff;
}
d[1] = 0;
for(j = 1; j <= n; j++)
{
int mark = -1;
double mindis = 0x7fffffff;
for(k = 1; k <= n; k++)
{
if(flag[k] == 0 && d[k] < mindis)
{
mindis = d[k];
mark = k;
}
}
flag[mark] = 1;
for(k = 1; k <= n; k++)
{
d[k] = (d[mark] > dis[mark][k] ? d[mark] : dis[mark][k]) > d[k] ? d[k] : (d[mark] > dis[mark][k] ? d[mark] : dis[mark][k]);
}
}
}
int main()
{ double x, y;
while(scanf("%d", &n) != EOF)
{
if(n == 0)
break;
int j, k;
for(j = 1; j <= n; j++)
{
scanf("%lf %lf", &x, &y);
map[j][0] = x;
map[j][1] = y;
for(k = 1; k < j; k++)
{
double temp;
temp = sqrt((x - map[k][0]) * (x - map[k][0]) + (y - map[k][1]) * (y - map[k][1]));
dis[j][k] = temp;
dis[k][j] = temp;
}
}
dij();
printf("Scenario #%d\nFrog Distance = %.3lf\n\n", i, d[2]);
i++;
}
return 0;
}
poj 2253 Frogger dijkstra算法实现的更多相关文章
- POJ 2253 - Frogger - [dijkstra求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...
- POJ 2253 Frogger floyd算法
题目:click here 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任意两坐标间是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元素都是这条通路中前后两个点的距离,这些距离中 ...
- 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 ...
- 最短路(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变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
- POJ 2253 Frogger(dijkstra变形)
http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- selenium+python自动化之xpath定位
在上一篇简单的介绍了用工具查看目标元素的xpath地址,工具查看比较死板,不够灵活,有时候直接复制粘贴会定位不到.这个时候就需要自己手动的去写xpath了,这一篇详细讲解xpath的一些语法. 什么是 ...
- 初试体验java多线程
现在个人电脑以及服务器都是多核cpu,如何提高多核cpu的利用率,就要用到多线程技术了. public class TestThread1 { ; static class PThread exten ...
- Android Studio 单元测试
测试的种类 按岗位划分 黑盒测试:测试逻辑业务 白盒测试:测试逻辑方法 按测试粒度分 方法测试:function test 单元测试:unit test 集成测试:integration test 系 ...
- svn钩子(hooks)
首先你需要搭建出自己的svn环境出来,并能成功导入导出,并且了解svn,这是看这篇文章的前提.... 出于公司开发部需要svn同步更新服务器代码,需要用到svn钩子(hooks)技术,以前从来没听过, ...
- jquery 事件绑定以及解绑定
var targetSelect = $("#@(Perfix)tbData tbody tr select[data-target]"); targetSelect.off(&q ...
- sphinx 配置实例
配置实例 3.1.数据源. 这里我们采用 mysql的数据源.具体情况如下: Mysql server:192.168.1.10 Mysql db :test Mysql 表:test.sphinx_ ...
- Python基础教程【读书笔记】 - 2016/7/4
希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第二波:第7章 更加抽象 [总览] 创建自己的对象,是Python的核心概念!Python被称为面向对象的语言.介绍如 ...
- 【转】深入分析 iBATIS 框架之系统架构与映射原理
深入分析 iBATIS 框架之系统架构与映射原理 iBATIS 通过 SQL Map 将 Java 对象映射成 SQL 语句和将结果集再转化成 Java 对象,与其他 ORM 框架相比,既解决了 Ja ...
- linux时间管理
/etc/sysconfig/clock 该配置文件可用来设置用户选择何种方式显示时间.如果硬件时钟为本地时间,则UTC设为0,并且不用设置环境变量TZ.如果硬件时钟为UTC时间,则要 ...
- Saltstack系列1:安装配置
安装 安装EPEL作为安装Ansible的yum源(CentOS6.4) rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release ...