POJ 2253 Frogger
题目链接:http://poj.org/problem?id=2253
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 38366 | Accepted: 12357 |
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 题目大意:input 第一行的n代表 在一个湖中有n个石头,接下来是每个石头的坐标,Freddy在第一个石头上,Fiona在第二个石头上,找出一条最短路径使的
Freddy跳到Fiona所在的石头上,输出这条路径中他需要跳的最远的一次的距离。 解题思路: 迪杰斯特拉算法的应用 将dis数组中的值变成最短路径中的最大权值
AC代码:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <iomanip>
using namespace std;
#define inf 999999999
double dis[];
int visit[];
double p[][];
int n;
void dijkstra()
{
int i,j,pos = ,minn;
memset(visit,,sizeof(visit));
visit[] = ;
dis[] = ;
for (i = ; i <= n; i ++)
dis[i] = p[][i]; for (i = ; i <= n; i ++)
{
minn = inf;
for (j = ; j <= n; j ++)
{
if (!visit[j] && dis[j] < minn)
{
minn = dis[j];
pos = j;
}
}
visit[pos] = ;
if (pos == )
break;
for (j = ; j <= n; j ++) //将dis数组中的值变成最短路径中的最大权值
{
if (!visit[j] && dis[j] > max(dis[pos],p[pos][j]))
dis[j] = max(dis[pos],p[pos][j]);
}
}
}
int main ()
{
double x[],y[];
int i,j,f = ;
while (~scanf("%d",&n))
{
if (n == )
break;
for (i = ; i <= n; i ++)
for (j = ; j <= n; j ++)
p[i][j] = inf; for (i = ; i <= n; i ++)
scanf("%lf%lf",x+i,y+i); for (i = ;i < n; i ++)
{
for (j = i+; j <= n; j ++)
{
double xx = x[i]-x[j];
double yy = y[i]-y[j];
p[j][i] = p[i][j] = (double)sqrt(xx*xx+yy*yy);
}
}
dijkstra();
printf("Scenario #%d\n",f ++);
//printf("Frog Distance = %.3lf\n",dis[2]); //不知道为什么这种输出一直WA 下面的AC
cout<<fixed<<setprecision()<<"Frog Distance = "<<dis[]<<endl; //setprecision需要加上头文件#include <iomanip>
cout<<endl;
}
}
POJ 2253 Frogger的更多相关文章
- 最短路(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 (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 ...
- poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))
传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- 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 Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
随机推荐
- POJ 2762 tarjan缩点+并查集+度数
Going from u to v or from v to u? Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15494 ...
- MM 不哭 (tyvj 1097)
题目大意: 一条数轴上有 n 个 MM 在哭,需要tcboy去安慰,tcboy 一开始站在第k个MM身边,每个MM 哭都会减掉tcboy的RP. 确定安慰MM的顺序使得RP扣得最少.求 min(Rp_ ...
- wp8.1 Study1: 页面导航&页面间值传递
摘要:wp8.1与wp8中很多API是不一样了,wp8.1把以前wp7.x时的api去掉了,更多与win8.1的API相似.比如以下的页面导航和页面之间的值传递 1.页面导航 利用Frame.Navi ...
- POJ 3525 半平面交+二分
二分所能形成圆的最大距离,然后将每一条边都向内推进这个距离,最后所有边组合在一起判断时候存在内部点 #include <cstdio> #include <cstring> # ...
- 蓝桥杯 ALGO-108 最大体积 (动态规划)
问题描述 每个物品有一定的体积(废话),不同的物品组 合,装入背包会战用一定的总体积.假如每个物品有无限件可用,那么有些体积是永远也装不出来的.为了尽量装满背包,附中的OIER想要研究一下物品不能装 ...
- 读取properties中的key对应的value
- Struts2 的ModelDriven理解
以UserAction为例,当UserAction实现了ModelDriven接口之后,与该接口相关的默认配置的拦截器会在拦截请求之后判断该请求是将要被UserAction处理而且UserAction ...
- electronic data interchange 电子数据交换
electronic data interchange 电子数据交换
- ubuntu下的wps不能使用中文.
首先如果wps不能用中文的话应该是 excell ppt word 都不能用 . 我的办法需要改三个文件 . 先后打开这三个文件 . xpower@xpower-CW65S:~$ sudo vim / ...
- 破解 crackme(完全拆解警告窗口)
系统 : Windows xp 程序 : crackme 程序下载地址 :http://pan.baidu.com/s/1kUrbcAr 要求 : 注册机编写 & 去除Nag窗口 使用工具 : ...