POJ 2253 Frogger(dijkstra变形)
http://poj.org/problem?id=2253
题意:
有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳。给出所有石头的坐标点,求出在所有通路中青蛙需要跳跃距离的最小值。
思路:
dijkstra算法的变形。本来是dist是记录最短距离,在这道题中可以把它变为已经跳过的最大距离,稍微改一下松弛算法就可以。具体见代码。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std; const int maxn = + ;
const int INF = 0x3f3f3f3f; int n;
int x[maxn], y[maxn];
double dist[maxn];
int vis[maxn]; double cacl(int x1, int y1, int x2, int y2)
{
return sqrt((double)(x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
} void dijkstra()
{
memset(vis, , sizeof(vis));
for (int i = ; i < n; i++)
{
bool flag = false;
double MIN = INF;
int u;
for (int j = ; j < n; j++)
{
if (!vis[j] && dist[j] < MIN)
{
MIN = dist[j];
flag = true;
u = j;
}
}
if (!flag) break;
if (u == ) break;
vis[u] = ;
for (int j = ; j < n; j++)
{
if (!vis[j] && dist[j]> max(dist[u], cacl(x[u], y[u], x[j], y[j])))
dist[j] = max(dist[u],cacl(x[u], y[u], x[j], y[j]));
}
}
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int kase = ;
while (~scanf("%d",&n) && n)
{
for (int i = ; i < n; i++)
scanf("%d%d", &x[i], &y[i]);
for (int i = ; i < n; i++)
{
dist[i] = cacl(x[], y[], x[i], y[i]);
}
dijkstra();
printf("Scenario #%d\n", ++kase);
printf("Frog Distance = %.3f\n\n", dist[]);
}
return ;
}
POJ 2253 Frogger(dijkstra变形)的更多相关文章
- poj 2253 Frogger dijkstra算法实现
点击打开链接 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21653 Accepted: 7042 D ...
- POJ 2253 - Frogger - [dijkstra求最短路]
Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...
- 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【最短路变形——路径上最小的最大权】
链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 2253 Frogger (dijkstra最短路)
题目链接: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:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
随机推荐
- 【Android】Android实现自定义带文字和图片的Button
在Android开发中经常会需要用到带文字和图片的button,下面来讲解一下常用的实现办法. 一.用系统自带的Button实现 最简单的一种办法就是利用系统自带的Button来实现,这种方式代码量最 ...
- Mysql limit offset用法举例
转自:http://blog.csdn.net/iastro/article/details/53037600 Mysql limit offset示例 例1,假设数据库表student存在13条数据 ...
- Git的配置和使用
eclipse中Git的配置 可以参考http://www.cnblogs.com/zhxiaomiao/archive/2013/05/16/3081148.html, http://blog.cs ...
- [Android Tips] 31.如何将第三库引入的 Permission 删除掉
Just declare the incriminated permission in your (main) Manifest with the tools:node="remove&qu ...
- java web 打印(lodop)案例
应需求接触到lodop 打印. 首先在lodop官网下载相关文件(js.css等):http://www.lodop.net/download.html 在下载好的包里 除了html页面 其他的j ...
- Spring boot官方文档学习(一)
个人说明:本文内容都是从为知笔记上复制过来的,样式难免走样,以后再修改吧.另外,本文可以看作官方文档的选择性的翻译(大部分),以及个人使用经验及问题. 其他说明:如果对Spring Boot没有概念, ...
- 转!!java 堆栈内存 对象实例等查看
https://blog.csdn.net/fenglibing/article/details/6411999
- Romantic---hdu2669(扩展欧几里德模板)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2669 详解:扩展欧几里德 #include <iostream> #include < ...
- Find them, Catch them---poj1703(并查集)
题目链接:http://poj.org/problem?id=1703 可以认为n个人和m句话: 每句话包含A a b;D a b; 刚开始关系不确定: A a b 就是问ab 是否同类: D a b ...
- 跟我学Makefile(四)
使用函数:函数调用,很像变量的使用,也是以“$”来标识的,其语法如下: $(<function> <arguments>) 或是 ${<function> < ...