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. 「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)

    题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是 ...

  2. MySQL日期函数、时间函数总结(MySQL 5.X)

    一.获得当前日期时间函数 1.1 获得当前日期+时间(date + time)函数:now() select now(); # :: 除了 now() 函数能获得当前的日期时间外,MySQL 中还有下 ...

  3. adb获取设备的序列号

    用数据线连接手机, 打开开发者模式, 并赋予相关权限, 在CMD命令行输入: adb devices 第一个参数即为设备的序列号, 第二个参数device表示设备的状态是在线.

  4. Java 输出对象为字符串 工具类

    public static String reflectionToString(Object o){ if(o == null) return StringUtils.EMPTY; StringBui ...

  5. 【system.array】使用说明

    对象:system.array 说明:提供一系列针对数组类型的操作 目录: 方法 返回 说明 system.array.join( array, separator ) [String]  将数组转换 ...

  6. 【MySQL解惑笔记】Centos7下卸载彻底MySQL数据库

    彻底卸载Yum安装的MySQL数据库 在我第二章MySQL数据库基于Centos7.3-部署过程中,因为以前安装过其它的版本所以没有卸载干净影响后期安装 一.卸载Centos7自带的Maridb数据库 ...

  7. day-15 用opencv怎么扫描图像,利用查找表和计时

    一.本节知识预览 1.  怎样遍历图像的每一个像素点? 2.  opencv图像矩阵怎么被存储的? 3.  怎样衡量我们算法的性能? 4.  什么是查表,为什么要使用它们? 二.什么是查表,为什么要使 ...

  8. SpringCloud IDEA 教学 (一) Eureka的简介与服务注册中心的建立

    写在开头 SpringCloud进来成为业界排名靠前的微服务框架,最核心功能就是搭建微服务,并在此基础上衍生出一系列功能,如断路器(Hystrix).断路监控.管理配置.Zuul.OAuth2等功能. ...

  9. 自测之Lesson13:共享内存

    题目:创建一个64K的共享内存. 实现代码: #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> ...

  10. Rescue(BFS时间最短 另开数组或优先队列)

    Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M ...