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 ...
随机推荐
- [Angular 2] Custom Validtors
Create a custom validtor which only accepts the string start with '123'; function skuValidator(contr ...
- nodejs这个过程POST求
下面是一个web登陆模拟过程.当我们问一个链接,你得到一个表格,然后填写相应的表格值,然后提交登陆. var http = require('http'); var querystring = req ...
- getconf 取系统配制 --CPU
cpu 缓存:getconf -a LEVEL1_ICACHE_SIZE LEVEL1_ICACHE_ASSOC LEVEL1_ICACHE_LINESIZE LEVEL1_DCACHE_SIZE L ...
- Valgrind简介:
Valgrind是动态分析工具的框架.有很多Valgrind工具可以自动的检测许多内存管理和多进程/线程的bugs,在细节上剖析你的程序.你也可以利用Valgrind框架来实现自己的工具. Valgr ...
- docker入门(二)
打造自己的镜像 首先我们启动busybox镜像为容器,在该容器中安装一个小工具,再将这个容器保存为新的镜像 首先我们下载一个镜像,再启动容器 [root@centos ~]# docker pull ...
- RuntimePermissions
This sample shows runtime permissions available in Android M and above. Display the log on screen to ...
- Miller_Rabin codevs 1702 素数判定2
/* 直接费马小定理 */ #include<iostream> #include<cstdio> #include<cstdlib> #include<ct ...
- 基于Bootstrap实现下图所示效果的页面,一个白底的带有两个菜单项、一个下拉菜单和一个登录表单的基本导航条
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...
- (转)JS的parent对象
---http://blog.sina.com.cn/s/blog_a15aa5690101a5yz.html top:该变更永远指分割窗口最高层次的浏览器窗口.如果计划从分割窗口的最高层次开始执行命 ...
- 【转】iOS开发系列--数据存取
原文: http://www.cnblogs.com/kenshincui/p/4077833.html#SQLite 概览 在iOS开发中数据存储的方式可以归纳为两类:一类是存储为文件,另一类是存储 ...