POJ. 2253 Frogger (Dijkstra )

题意分析

  1. 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标。给出的n个点,两两双向互通,求出由1到2可行通路的所有步骤当中,步长最大值。
  2. 在dij原算法的基础上稍作改动即可。dij求解的是单源最短路,现在求解的是步长最大值,那么更新原则就是,当前的这一步比保存的步如果要大的话,就更新,否则就不更新。
  3. 如此求解出来的就是单源最大步骤。

代码总览

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#define nmax 205
#define inf 1e8+7
using namespace std;
typedef struct{
int x,y;
}ston;
ston stone[nmax];
double mp[nmax][nmax];
double shortpath[nmax];
double ans[nmax];
bool visit[nmax];
int n;
double cal(ston a ,ston b)
{
return sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) );
}
void dij(int s)
{
int cur = s;
memset(visit,0,sizeof(visit));
for(int i = 1;i<=n;++i){shortpath[i] = inf;ans[i]=inf;}
shortpath[cur] = 0;
visit[cur] = true;
int temptag;
for(int i = 1;i<=n ;++i){
double minL = inf;
for(int j = 1;j<=n;++j){
double dist;
if(!visit[j] && max(shortpath[cur] , mp[cur][j]) < shortpath[j]){
dist = max(shortpath[cur] , mp[cur][j]);
shortpath[j] = dist;
}
if(!visit[j] && minL>shortpath[j]){
minL = shortpath[j];
temptag = j;
}
}
if(minL == inf) return;
cur = temptag;
visit[cur] = true;
}
}
void init()
{
for(int i = 1;i<=n;++i)
for(int j = 1;j<=n;++j)
mp[i][j] = inf;
for(int i = 1;i<=n;++i){
scanf("%d %d",&stone[i].x,&stone[i].y);
}
for(int i = 1;i<=n;++i){
for(int j = 1;j<=n;++j){
if(i!=j){
mp[i][j] = mp[j][i] = cal(stone[i],stone[j]);
}
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
int kase = 1;
while(scanf("%d",&n)!= EOF && n!=0){
init();
dij(1);
printf("Scenario #%d\n",kase++);
printf("Frog Distance = %.3f\n\n",shortpath[2]); }
return 0;
}

POJ. 2253 Frogger (Dijkstra )的更多相关文章

  1. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  2. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  3. POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)

    题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...

  4. POJ 2253 Frogger(dijkstra变形)

    http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...

  5. POJ 2253 Frogger(Dijkstra)

    传送门 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39453   Accepted: 12691 Des ...

  6. POJ - 2253 Frogger(Dijkstra变形题)

    题意: 题目撰写者的英语真是艰难晦涩,看了别人题解,才知道这题题意. 两个forger 一个froger 要蹦到另外一个froger处,他们的最短距离是这样定义的 : The frog distanc ...

  7. POJ 2253 Frogger (dijkstra 最大边最小)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...

  8. POJ 2253 Frogger (Dijkstra变型)

    题意:求点1到点2的路径中,权值最大的那条边,其最小值是多少. 分析:最大值最小化.可以将迪杰斯特拉模板中的松弛操作加以修改,在O(n^2)的时间内解决该问题.其中需要注意的是,dist[i]指的是: ...

  9. POJ - 2253 Frogger(最短路Dijkstra or flod)

    题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...

随机推荐

  1. JavaWeb(三)——Tomcat服务器(二)

    一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命令的用法如下:

  2. 如何利用Navicat导入/导出mssql中的数据

    sqlserver,在第一次使用该软件进行"连接"的时候,会提示安装"Microsoft Sqlsever Navicat Client.",这时直接点击&qu ...

  3. mybati缓存机制之二级缓存配置

    二级缓存配置 在MyBatis的配置文件中开启二级缓存. <setting name="cacheEnabled" value="true"/> 在 ...

  4. Python 更换国内pip源

    pip国内的一些镜像: 阿里云 http://mirrors.aliyun.com/pypi/simple/   中国科技大学 https://pypi.mirrors.ustc.edu.cn/sim ...

  5. ADB连接不上手机,端口5037被占用的情况解决

    最近在搞手机APP自动化测试,adb连接手机时提示端口被占用 检测5037端口被谁占用,cmd窗口输入命令:netstat -ano | findstr "5037" (注意”50 ...

  6. Linux命令应用大词典-第9章 数字计算

    9.1 bc:任意精度的计算器 9.2 dc:一个任意精度的计算器 9.3 expr:将表达式的值打印到标准输出 9.1 bc:任意精度的计算器 9.2 dc:一个任意精度的计算器 9.3 expr: ...

  7. Response对象及常用方法

    void addCookie(Cookie cookie)给客户端添加一个Cookie对象,以保存客户端的信息 void addDateHeader(String name,long value) 添 ...

  8. servlet和Jsp的复习整理

    servlet 1.生命周期 a.构造方法.生成一个servlet b.init()方法.当开启服务器时,servlet第一次被装载,servlet引擎调用这个servlet的init()的方法,只调 ...

  9. lintcode: Check Sum of Square Numbers

    Check Sum of Square Numbers Given a integer c, your task is to decide whether there're two integers ...

  10. spark-submit配置说明

    <Spark 官方文档>Spark配置 spark-1.6.0 原文地址 Spark配置 Spark有以下三种方式修改配置: Spark properties (Spark属性)可以控制绝 ...