POJ2253 Frogger(最短路)
题目链接。
题意:
从0号点,到1号点,找一条能通过的路,使得这条路中的最大的边,比其它所有可能的路中的边都小。
分析:
这题就是按着dijkstra写,写着写着觉得像是prim了。
其中d[n]表示从0出发到达该点的某条路中的最大边,且比其它可能的路中的都小。
从d[i]到d[j], 就是要用 max(d[i], G[i][j]) 去更新 d[j] 。
注意:
输出时要用 %.3f 不能用 %.3lf.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <cmath> using namespace std; const int maxn = ; const double INF = 1e60; int n;
double G[maxn][maxn], d[maxn]; struct Pos {
int x, y;
}num[maxn]; double calc(int i, int j) {
return (sqrt(pow((double)num[i].x-num[j].x, )+pow((double)num[i].y-num[j].y, )));
} double dijkstra() {
bool vis[maxn]; memset(vis, false, sizeof(vis)); for(int i=; i<n; i++) {
d[i] = G[][i];
} d[] = ;
vis[] = true; for(int i=; i<n-; i++) {
double m = INF; int x;
for(int y=; y<n; y++) if(!vis[y] && m >= d[y]) m = d[x=y];
vis[x] = true;
for(int y=; y<n; y++){
if(!vis[y]) {
double maxx = max(d[x], G[x][y]);
if(d[y] > maxx) d[y] = maxx;
}
}
} return d[];
} int main() {
int cnt = ;
while(scanf("%d", &n) == ) {
if(n == ) break; for(int i=; i<n; i++) scanf("%d%d", &num[i].x, &num[i].y); for(int i=; i<n; i++) {
for(int j=; j<i; j++) {
G[i][j] = G[j][i] = calc(i, j);
}
G[i][i] = ;
} printf("Scenario #%d\nFrog Distance = %.3f\n\n", ++cnt, dijkstra());
} return ;
}
POJ2253 Frogger(最短路)的更多相关文章
- POJ2253 Frogger —— 最短路变形
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ2253 frogger 最短路 floyd
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#inc ...
- POJ-2253 Frogger(最短路)
https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...
- POJ-2253.Frogger.(求每条路径中最大值的最小值,最短路变形)
做到了这个题,感觉网上的博客是真的水,只有kuangbin大神一句话就点醒了我,所以我写这篇博客是为了让最短路的入门者尽快脱坑...... 本题思路:本题是最短路的变形,要求出最短路中的最大跳跃距离, ...
- poj2253 Frogger(最短路变型或者最小生成树)
/* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...
- Frogger(最短路)
Frogger(poj2253) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 31854 Accepted: 1026 ...
- poj2253 Frogger(Floyd)
题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算 ...
- POJ2253 Frogger
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34865 Accepted: 11192 Descrip ...
- POJ 2253 Frogger (最短路)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28333 Accepted: 9208 Descript ...
随机推荐
- Java模块化概念解惑与现状总结
在过去几年,Java模块化一直是一个活跃的话题.从JSR 277(现已废止)到JSR 291,模块化看起来是Java进化过程中的必经一环.即便是基于JVM的未来语言,比如Scala,也考虑了模块化的问 ...
- iOS UI布局调试工具
查看ios软件的ui布局有三种: 1.DCIntrospect 这种方式是开源的,我从github上clone下来后运行demo,运行遇到了问题:Xcode cannot run using t ...
- dispatch的几种队列
dispatch的几种队列 dispatch队列的生成可以有这几种方式: 1. dispatch_queue_t queue = dispatch_queue_create("com.d ...
- NYOJ 47过河问题
主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...
- HDU5327
#include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...
- Sql语句 不支持中文 国外数据库
由于老美的不支持中文 SQL 语句第一:字段类型改为nvarchar,ntext 第二:强制转化 N update dbo.Role set rolename=N'普通用户' update dbo.T ...
- Js数学函数1
1.取模求余数 //1.JS取模求余 //输出 for (var i = 0; i < 20; i++) { if (i % 3 == 0) { documentHelper.WriteText ...
- sencha app build 到 Capturing theme image不执行
解决sencha app build 到 Capturing theme image不执行 今天电脑重装系统,重新安装了sencha cmd,但是在打包时,到了 Capturing theme ima ...
- JavaScript那些事儿(01): 对象
一. 对象是什么 是单身童鞋们正在查找的“对象”吗?是的,他/她就是活生生的对象. Javascript是一种基于对象的语言, 你遇到的所有东西几乎都是对象. 但它又不同于基于类的语言.那么“类”又是 ...
- ERROR:the server has either erred or is incapable of performing the requested operation
openstack中,有时会经常出现这种错误,原因无二,一是安全组没有设置正确,二是openstack中网络配置会有些问题或者是相关的服务没有启动. 解决方法:1.安全组问题在nova.conf和ne ...