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 ...
随机推荐
- 【BZOJ3678】wangxz与OJ Splay
[BZOJ3678]wangxz与OJ Description 某天,wangxz神犇来到了一个信息学在线评测系统(Online Judge).由于他是一位哲♂学的神犇,所以他不打算做题.他发现这些题 ...
- 解决Activity启动黑屏及设置android:windowIsTranslucent不兼容activity切换动画问题
From:http://blog.csdn.net/fancylovejava/article/details/39643449 之前在做 APP 的时候不太关注这个问题,因为自己在使用其他 APP ...
- PHP概率算法---砸金蛋示例
这是一个很经典的概率算法: function get_rand($proArr) { $result = ''; //概率数组的总概率精度 $proSum = array_sum($proArr); ...
- 170531、FormData 对象的使用
通过FormData对象可以组装一组用 XMLHttpRequest发送请求的键/值对.它可以更灵活方便的发送表单数据,因为可以独立于表单使用.如果你把表单的编码类型设置为multipart/form ...
- jenkins之配置git认证方式
在使用jenkins构建时候需要从git下拉代码,需要配置认证方式 http拉取代码 配置用户名和密码认证 添加认证 设置用户名和密码 git认证 设置私钥认证
- Centos6.5SSH登录使用google二次验证
一般ssh登录服务器,只需要输入账号和密码,但为了更安全,在账号和密码之间再增加一个google的动态验证码.谷歌身份验证器生成的是动态验证码,默认30秒更新 工具/原料 CentOS 6.5 X ...
- 解决Android版Firefox字体显示过大的问题
在用Android版Firefox查看博客园首页发现中间区域的字体显示非常大,开始以为是首页css对移动版浏览器支持不好. 后来发现原来这是Firefox for Android的知名bug: Tha ...
- 虚拟机中CentoOs配置ip且连网
1.修改"VMware Network Adapter VMnet8",配置IP 2.打开虚拟机,"编辑" => "虚拟网络编辑器", ...
- 各大互联网企业Java面试题汇总,看我如何成功拿到百度的offer
前言 本人Java开发,5年经验,7月初来到帝都,开启面试经历,前后20天左右,主面互联网公司,一二线大公司或者是融资中的创业公司都面试过,拿了一些offer,其中包括奇虎360,最后综合决定还是去百 ...
- 一次tns连接错误的解决过程
--同事hadoop连接oracle导入数据,界面报错,后台alert日志报错tns相关错误: **************************************************** ...