(最短路 Floyd diskstra prim)Frogger --POJ--2253
题目链接:http://poj.org/problem?id=2253
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31114 | Accepted: 10027 |
Description
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.
Input
Output
Sample Input
2
0 0
3 4 3
17 4
19 4
18 5 0
Sample Output
Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
题意:
Floyd
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; #define INF 0x3f3f3f3f
#define N 300
struct node
{
int x, y;
}; double dist[N];
double G[N][N];
int vis[N], n; void IN()
{
memset(vis, , sizeof(vis)); for(int i=; i<=n; i++)
{
dist[i]=INF;
for(int j=; j<=i; j++)
G[i][j]=G[j][i]=INF;
}
} void Floyd()
{
for(int k=; k<=n; k++)
{
for(int j=; j<=n; j++)
{
for(int i=; i<=n; i++)
{
if(G[j][i] > max(G[j][k], G[k][i]))
G[j][i] = max(G[j][k], G[k][i]);
}
}
}
} int main()
{
int i, j, t=; while(scanf("%d", &n), n)
{
double w;
node s[N];
memset(s, , sizeof(s));
IN(); for(i=; i<=n; i++)
scanf("%d%d", &s[i].x, &s[i].y); for(i=; i<n; i++)
for(j=i+; j<=n; j++)
{
w = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)*1.0 + (s[i].y-s[j].y)*(s[i].y-s[j].y)*1.0);
G[i][j] = G[j][i]=min(G[i][j], w);
} printf("Scenario #%d\n", t++); Floyd(); printf("Frog Distance = %.3f\n\n", G[][]); }
return ;
}
dijkstra
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue> using namespace std; #define INF 0xfffffff
#define N 1100
struct node
{
int x, y;
}a[N]; int n, vis[N];
double dist[N], G[N][N]; void Dij()
{
int i, j; for(i=; i<=n; i++)
{
dist[i] = G[][i];
vis[i] = ;
}
vis[] = ; for(i=; i<n; i++)
{
int index=;
double Min=INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<Min)
{
Min = dist[j];
index = j;
}
} if(index==)
continue; vis[index] = ; for(j=; j<=n; j++)
if(!vis[j] && max(dist[index], G[index][j])<dist[j])
dist[j] = max(dist[index], G[index][j]);
}
} int main()
{
int iCase = ; while(scanf("%d", &n), n)
{
int i, j; for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
{
double d = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) );
G[i][j] = G[j][i] = d;
} Dij();
printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", dist[]);
}
return ;
}
prim
类似于最小生成树
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int INF = (<<)-;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define N 1100 struct node
{
int x, y;
}a[N]; int n, m;
double dist[N], G[N][N];
int vis[N]; double prim()
{
int i, j;
double ans = -; for(i=; i<=n; i++)
dist[i] = G[][i];
dist[] = ; memset(vis, , sizeof(vis));
vis[] = ; for(i=; i<=n; i++)
{
int index = ;
double Min = INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<=Min)
{
Min = dist[j];
index = j;
}
} if(index==) break; vis[index] = ; ans = max(ans, Min); if(index==) return ans; for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]>G[index][j])
dist[j] = G[index][j];
}
} return ans;
} int main()
{
int iCase=;
while(scanf("%d", &n), n)
{
int i, j; memset(a, , sizeof(a)); for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
G[i][j] = G[j][i] = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) ); printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", prim());
}
return ;
}
(最短路 Floyd diskstra prim)Frogger --POJ--2253的更多相关文章
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)
题意 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...
- Frogger POJ - 2253
题意 给你n个点,1为起点,2为终点,要求所有1到2所有路径中每条路径上最大值的最小值. 思路 不想打最短路 跑一边最小生成树,再扫一遍1到2的路径,取最大值即可 注意g++要用%f输出!!! 常数巨 ...
- kuangbin专题专题四 Frogger POJ - 2253
题目链接:https://vjudge.net/problem/POJ-2253 思路: 从一号到二号石头的所有路线中,每条路线中都个子选出该路线中两点通路的最长距离,并在这些选出的最长距离选出最短路 ...
- Frogger - poj 2253 (Dijkstra)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28802 Accepted: 9353 Description Fr ...
- 最短路(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 (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
随机推荐
- 定时器中的this和函数封装的简单理解;
一.定时器中的this: 不管定时器中的函数怎么写,它里面的this都是window: 在函数前面讲this赋值给一个变量,函数内使用这个变量就可以改变this的指向 二.函数封装 函数封装是一种函数 ...
- overflow visibility opacity(透明度) vertical-align 等等
一,overflow属性: 1,四个值: visible 默认值.内容不会被修剪,会呈现在元素框之外. hidden 内容会被修剪,并且其余内容是不可见的. ...
- layer.confirm在ASP.NET控件onclick上面的应用方法
有些时候,你可能要修改控件的事件,元素本身.等,这个时候如何操作呢?下面提供一个思路: <asp:LinkButton Visible="false" ID="sh ...
- UVALive - 3266 (贪心) 田忌赛马
耳熟能详的故事,田忌赛马,第一行给出田忌的马的速度,第二行是齐王的马的速度,田忌赢一场得200,输一场失去200,平局不得也不失,问最后田忌最多能得多少钱? 都知道在故事里,田忌用下等马对上等马,中等 ...
- wmi uuid
[转]https://www.cnblogs.com/-sylar/p/8376621.html 1. 开始-运行-输入:wbemtest 回车2. 单击"连接", 输入:root ...
- [Jmeter] Run Command to generate a specific listener’s chart report
Run Command to generate a specific listener’s chart report: Download cmdrunner-2.0.jar : https://jme ...
- Spring 注解(一)Spring 注解编程模型
Spring 注解(一)Spring 注解编程模型 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) Spring 注解系列 ...
- service fabric重装电脑后集群失败
前提.下载service fabric sdk工具 1.Remote Procedure Call (RPC)服务打开 自动 2.Remote Procedure Call (RPC) Locator ...
- 安装crf++
在这里就不提心酸的安装过程了,就把成功安装及部分问题整理出来,以供参考: 安装环境:ubuntu14 1.安装ruby包 sudo apt-get install ruby2.安装zlib包 su ...
- springMVC学习一 工作机制
springMVC下面的四大组件: (1)DispatcherServlet : 前端控制器,接收所有请求 ,并把请求路径和请求参数解析出来,本质是一个servlet在web.xml中配置 (如果配置 ...