Frogger - poj 2253 (Dijkstra)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 28802 | Accepted: 9353 |
Description
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
Output
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,将松弛条件改一下就可以了,改成
if(dis[j]>max(dis[stone],map[stone][j])&&(vis[j]==0)){
dis[j]=max(dis[stone],map[stone][j]);
}
这样的结果就是求得能到达这点的路径上的最长边的最小值,求输出时要注意格式
#include <iostream>
#include<math.h>
#include<limits.h>
#include<algorithm>
#include<iomanip>
using namespace std;
int num;
int vis[],stone[][];
int map[][],dis[];
int Dijkstra(){
for(int i=;i<num;i++){
dis[i]=INT_MAX;
vis[i]=;
}
dis[]=;
for(int i=;i<num;i++){
int min=INT_MAX;
int stone;
for(int j=;j<num;j++){
if((vis[j]==)&&min>dis[j]){
stone=j;
min=dis[j];
}
}
vis[stone]=;
if(min==INT_MAX)
break;
for(int j=;j<num;j++){
if(dis[j]>max(dis[stone],map[stone][j])&&(vis[j]==)){
dis[j]=max(dis[stone],map[stone][j]);
}
}
}
return dis[];
} int main() { cin>>num;
int count=;
while(num){
for(int i=;i<num;i++){
cin>>stone[i][]>>stone[i][];
}
for(int i=;i<num;i++){
for(int j=;j<num;j++){
map[i][j]=pow((stone[i][]-stone[j][]),)+pow((stone[i][]-stone[j][]),);
}
}
float fdis=sqrt(Dijkstra());
cout<<fixed;
cout<<"Scenario #"<<count<<endl<<"Frog Distance = "<<setprecision()<<fdis<<endl<<endl; count++;
cin>>num;
} return ;
}
Frogger - poj 2253 (Dijkstra)的更多相关文章
- Poj(2253),Dijkstra松弛条件的变形
题目链接:http://poj.org/problem?id=2253 题意: 给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通 ...
- Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)
题意 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...
- kuangbin专题专题四 Frogger POJ - 2253
题目链接:https://vjudge.net/problem/POJ-2253 思路: 从一号到二号石头的所有路线中,每条路线中都个子选出该路线中两点通路的最长距离,并在这些选出的最长距离选出最短路 ...
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- Frogger POJ - 2253
题意 给你n个点,1为起点,2为终点,要求所有1到2所有路径中每条路径上最大值的最小值. 思路 不想打最短路 跑一边最小生成树,再扫一遍1到2的路径,取最大值即可 注意g++要用%f输出!!! 常数巨 ...
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- 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& ...
随机推荐
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
- nginx的location匹配
http://www.cnblogs.com/lidabo/p/4169396.html 这个博主写的非常好 location: 先匹配普通location,再匹配正则表达式 1.而且选择了最大前缀匹 ...
- 事务没有提交导致 锁等待Lock wait timeout exceeded异常
异常:Lock wait timeout exceeded; try restarting transaction 解决办法: 执行select * from information_schema.i ...
- Quartz配置CronTrigger
CronTrigger 构造器 String name, //触发器名称 String group, //触发器的组名 String jobName, //job名称 String jobGroup, ...
- 遨游maxthon打开页面一片黑色,百度地图等黑屏解决办法
遨游maxthon使用webkit极速核心,打开百度地图等页面一片黑色,黑屏了. 找了好久,不知道什么问题. 版本一样,都是4.4.xxx版本.另外一台机器又正常. 后来上傲游社区,好多人也有这个问题 ...
- ASP.NET MVC学习---(三)EF简单增删改查
那么现在我们已经大概从本质上了解了ef 巴拉巴拉说了一大堆之后 总算要进入ef的正题了 总在口头说也太不行了是吧~ 没错,现在要用ef进行一些实际的操作 做什么呢? 就做一个入门级的增删改查操作吧 废 ...
- 2017.4.28 SSM框架搭建与配置
1.项目结构 2.配置文件 对配置文件进行总结: pom.xml web.xml -> 配置web相关 -> 读取application*.xml 5 -> 读取logback.xm ...
- EffectiveJava(3)使用是由构造器或枚举类型强化singleton
使用是由构造器或枚举类型强化singleton 普通singleton:借助AccessibleObject.setAssess方法,通过反射机制调用私有构造器.抵御这种攻击可以修改构造器,让其再被要 ...
- 使用Java取得本机IP和机器名
try { InetAddress addr = InetAddress.getLocalHost(); String ip=addr.getHostAddress().toString();//获得 ...
- 微信小程序 - 替换tabbar(采用固定定位形式)
简单示例(提供思路): wxml(作为模板形式插入到需要tabbar的地方去) <view class='tab-bar'> <view class="usermotto& ...