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变形)的更多相关文章

  1. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  2. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  6. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  7. POJ 2253 Frogger【最短路变形——路径上最小的最大权】

    链接: http://poj.org/problem?id=2253 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  8. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  10. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

随机推荐

  1. 启动Solr时报 _version_ field must exist in schema 错误的解决方法

    Solr启动时报 org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Unable to use up ...

  2. Minix2.0操作系统kernel文件分析

    详细分析  MINIX消息机制的核心: mpx386.s start.c proc.c 保护模式分析: src/kernel/exception.c src/kernel/protect.c src/ ...

  3. 【BZOJ4524】[Cqoi2016]伪光滑数 堆(模拟搜索)

    [BZOJ4524][Cqoi2016]伪光滑数 Description 若一个大于1的整数M的质因数分解有k项,其最大的质因子为Ak,并且满足Ak^K<=N,Ak<128,我们就称整数M ...

  4. java 空间四点定位,可跟据已知的四点坐标(x,y,z)及距离计算所在位置坐标

    public static void main(String args[]) { try{ float point[]=new float[3]; Location loc = new Locatio ...

  5. mac必装工具以及mac使用介绍

    必装工具 Scroll Reverserhttp://pilotmoon.com/scrollreverser/:一款可以使得鼠标使用方式和windows系统一致的软件 编程工具 ,,,,, 常用快捷 ...

  6. onethink重新安装后,还原数据库后,登陆不了解决办法!

    在用onethink开发的时候,为了防止修改出错,我会在开发下一个功能的对上一个功能代码整体进行备份,如果出错就返回上一个版本再次修改. 但是会发现一个问题,如果如果返回到上一个版本,重新安装完成之后 ...

  7. 9.SQL存储过程实例详解

    本文用3个题目,从建立数据库到创建存储过程,详细讲解数据库的功能. 题目1 学校图书馆借书信息管理系统建立三个表:学生信息表:student 字段名称 数据类型 说明 stuID char(10) 学 ...

  8. JS生成GUID方法

    function GUID() { this.date = new Date(); /* 判断是否初始化过,如果初始化过以下代码,则以下代码将不再执行,实际中只执行一次 */ if (typeof t ...

  9. Oracle涂抹oracle学习笔记第8章RMAN说,我能备份

    本次测试服务器为172.16.25.33 使用rman连接本地数据库 rman target / 在rman中执行启动与关闭的命令与sqlplus相同 在rman中执行sql语句 sql ‘需要执行的 ...

  10. RabbitMQ(转)

    add by zhj: 如果用Python,那可以用celery,它是一个分布式任务队列,它的broker可以选择Rabbitmq/Redis/Mongodb等, celery通过Kombu这个lib ...