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. python 进行抓包嗅探

    一.绪论 最近一直想弄一个代理,并且对数据包进行解读,从而完成来往流量的嗅探.于是今天学习了一下如何使用Python抓包并进行解包. 首先要用到两个模块 dpkt(我这边ubuntu16.04 LTS ...

  2. sort排序和uniq统计命令

    author:headsen chen date: 2018-08-13  11:08:09 1,sort:排序的功能,默认安装ASCII码来排序,-n 安装数值排,-r 按照倒序来排 [root@b ...

  3. Egret3D学习笔记一 (Unity插件使用)

    一 官方教程: http://developer.egret.com/cn/github/egret-docs/Engine3D/getStarted/getStarted/index.html 大部 ...

  4. C#文件下载的几种方式

    第一种:最简单的超链接方法,<a>标签的href直接指向目标文件地址,这样容易暴露地址造成盗链,这里就不说了 1.<a>标签 <a href="~/Home/d ...

  5. ios UIImage图片拉伸 resizableImageWithCapInsets:

    常见的按钮添加和背景设置如下: UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(80, 130, 160, 44)];[bu ...

  6. Mac - 苹果电脑mac系统释放硬盘空间方法汇总

    硬盘空间是大家最头痛的一个问题,大家在硬盘空间变小的时候怎么腾空间的呢?下面为大家分享7个mac系统释放空间的高级方法,大家赶紧来收了! mac系统释放硬盘空间方法: 方法一:删除Emacs--可以节 ...

  7. CodeForeces 25E (kmp)

    E. Test time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputst ...

  8. https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic net::ERR_CONNECTION_TIMED_OUT问题解决

    使用adminTLE时,有时候出现 https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic, ...

  9. Python开发【模块】:内置模块

    内置模块 1.__import__ # import app目录下的kingadmin.py文件 for app in conf.settings.INSTALLED_APPS: __import__ ...

  10. (2.3)DDL增强功能-流程化控制与动态sql

    1.流程控制 在T-SQL中,与流程控制语句相关的关键字有8个: BEGIN...END BREAK GOTO CONTINUE IF...ELSE WHILE RETURN WAITFOR 其实还可 ...