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& ...
随机推荐
- luogu P2776 [SDOI2007]小组队列
题目背景 嘛,这道非常简单的给大家提供信心的省选题洛谷居然没有! 这么简单的题怎么可以没有! 给大家提升士气是义不容辞的责任! 所以我就来补一下啦.. 值得一提的是,标程是我自己做的.. 很渣,因为数 ...
- 1.14(java学习笔记)数组
假如我们需要用到1000个相同类型的数据,肯定不可能创建1000个变量, 这样既不方便,也不直观,也不便于我们使用.这时就需要用到数组. 一.数组的声明与使用 public class Array { ...
- 用kermit通过串口往nandflash任意地址里烧写任何文件!
1.安装kermit #apt-get install ckermit 2.使用kermit之前,在用户宿主目录下(/home/用户名/)创建一个名为.kermrc的配置文件,内容如下 : set l ...
- Word中设置所有西文字体为新罗马
如图所示,不用一个一个设置,在字体里直接设置细纹字体:Times New Roman ,中文字体不用管.
- Vue.js 2.0源码解析之前端渲染篇
一.前言 Vue.js框架是目前比较火的MVVM框架之一,简单易上手的学习曲线,友好的官方文档,配套的构建工具,让Vue.js在2016大放异彩,大有赶超React之势.前不久Vue.js 2.0正式 ...
- JAVA实现通用日志记录
原文:http://blog.csdn.net/jinzhencs/article/details/51882751 前言: 之前想在filter层直接过滤httpServerletRequest请求 ...
- TDD的iOS开发初步以及Kiwi使用入门
测试驱动开发(Test Driven Development,以下简称TDD)是保证代码质量的不二法则,也是先进程序开发的共识.Apple一直致力于在iOS开发中集成更加方便和可用的测试,在Xcode ...
- DoTween 部分中文文档
前言 DOTween现在还处于 alpha,所以还有一些缺失的功能(如路径插件,附加回调和其它的tween选项),这个文档在不久的将来可能会改变. 一.术语 Tweener 一个tween控制valu ...
- 【java】java自带的java.util.logging.Logger日志功能
偶然翻阅到一篇文章,注意到Java自带的Logger日志功能,特地来细细的看一看,记录一下. 1.Java自带的日志功能,默认的配置 ①Logger的默认配置,位置在JRE安装目录下lib中的logg ...
- EOS,RTOS,GUI
RTOS:(实时多任务操作系统) Real-time Operation System EOS:(嵌入式操作系统) Embedded Operation System GUI:(图形用户接口) G ...