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 ...
随机推荐
- jQuery中怎么添加innerText、innerHtml(转)
发现如果我在div或者其他非表单的标签中赋值,原本用普通的js就直接document.getElementById("id").innerHtml(或者其他几个)就可以了. 但是在 ...
- windows系统安装MongoDB
最近一直在学习node.js,nodejs开发指南中有一个微博的web开发项目,由于该书出的比较早(2012出的),目前为止利用nodejs进行web开发各种组合技术都发生了很大的更新,例如书中选择的 ...
- Hadoop学习地址
hortonworks: http://zh.hortonworks.com/hdp/downloads/ http://zh.hortonworks.com/hadoop-tutorial/supe ...
- R提高篇(四): 数据管理二
目录: 数学函数 统计函数 应用示例 控制流 数学函数 ceiling(x): 大于等于 x 的最小整数, 如: ceiling(3.213) --> 4 floor(x): 小 ...
- 我对javascript的自以为是
参数的作用域 if(true){ var tester = "Hello World"; } console.log(tester); 按照以往的经验,觉得上面的代码会报错,而实际 ...
- 使用laravel的Eloquent模型获取数据库的指定列
使用laravel的Eloquent模型获取数据库的指定列 使用Laravel的ORM——Eloquent时,时常遇到的一个操作是取模型中的其中一些属性,对应的就是在数据库中取表的特定列. 如果使 ...
- Linux下高并发socket最大连接数所受的各种限制
http://blog.csdn.net/guowake/article/details/6615728 1.修改用户进程可打开文件数限制 在Linux平台上,无论编写客户端程序还是服务端程序,在进行 ...
- Chrome插件开发入门(二)——消息传递机制
Chrome插件开发入门(二)——消息传递机制 由于插件的js运行环境有区别,所以消息传递机制是一个重要内容.阅读了很多博文,大家已经说得很清楚了,直接转一篇@姬小光 的博文,总结的挺好.后面附一 ...
- Codeforces Round #366 (Div. 2) C Thor(模拟+2种stl)
Thor 题意: 第一行n和q,n表示某手机有n个app,q表示下面有q个操作. 操作类型1:app x增加一条未读信息. 操作类型2:一次把app x的未读信息全部读完. 操作类型3:按照操作类型1 ...
- UNIX网络编程
UNIX网络编程--socket的keep http://www.68idc.cn/help/opersys/unixbsd/20150731471448.html