POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra )
题意分析
- 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标。给出的n个点,两两双向互通,求出由1到2可行通路的所有步骤当中,步长最大值。
- 在dij原算法的基础上稍作改动即可。dij求解的是单源最短路,现在求解的是步长最大值,那么更新原则就是,当前的这一步比保存的步如果要大的话,就更新,否则就不更新。
- 如此求解出来的就是单源最大步骤。
代码总览
#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 )的更多相关文章
- 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 (dijkstra最短路)
题目链接: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 Description Freddy Frog is sitting on a stone in the middle of ...
- POJ 2253 Frogger(dijkstra变形)
http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...
- POJ 2253 Frogger(Dijkstra)
传送门 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39453 Accepted: 12691 Des ...
- POJ - 2253 Frogger(Dijkstra变形题)
题意: 题目撰写者的英语真是艰难晦涩,看了别人题解,才知道这题题意. 两个forger 一个froger 要蹦到另外一个froger处,他们的最短距离是这样定义的 : The frog distanc ...
- POJ 2253 Frogger (dijkstra 最大边最小)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...
- POJ 2253 Frogger (Dijkstra变型)
题意:求点1到点2的路径中,权值最大的那条边,其最小值是多少. 分析:最大值最小化.可以将迪杰斯特拉模板中的松弛操作加以修改,在O(n^2)的时间内解决该问题.其中需要注意的是,dist[i]指的是: ...
- POJ - 2253 Frogger(最短路Dijkstra or flod)
题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...
随机推荐
- 初识java atomic
2018-8-19 昨天看到java.util.concurrent.atomic相关的文章,之前有过留意但并未去了解,正好有空学习一下.本人理解atomic包是concurrent子包,当是为并发所 ...
- python3 爬虫爬取深圳公租房轮候库(深圳房网)
深圳公租房轮候库已经朝着几十万人的规模前进了,这是截至16年10月之前的数据了,贴上来大家体会下 所以17年已更新妥妥的10W+ 今天就拿这个作为爬虫的练手项目 1.环境准备: 操作系统:win10 ...
- .NET MVC和.NET WEB api混用时注意事项
1.同时配置了mvc路由和api路由时,mvc路由无法访问(调用所有mvc路由全部404错误) 在Global.asax中,需注意路由注册的顺序,将api路由注册放在最后: 即将 void Appli ...
- <cfenv>(fenv.h) _c++11
头文件 <cfenv>(fenv.h) c++11 浮点环境 这个头文件声明了一系列的函数和宏去访问浮点环境,以及特殊的类型. 浮点环境维护一系列的状态标志(status flags)和具 ...
- python终极篇 ---django 模板系统
模板系统 . MV ...
- POJ - 3259
要判断是否有负的权值 #include<iostream> #include<stdio.h> #include<algorithm> #include<st ...
- org.apache.spark.launcher.Main源码分析
public static void main(String[] argsArray) throws Exception { //org.apache.spark.launcher.Main chec ...
- [Install] TeamViewer
安装TeamViwer 1. $ sudo apt-get -f install 2. 使用gdebi安装TeamViwer. 所以先安装gdebi package. $ sudo apt-get i ...
- Python面向对象-类成员
类的成员可以分为三大类:字段.方法和属性: 注:所有成员中,只有普通字段的内容保存对象中,即:根据此类创建了多少对象,在内存中就有多少个普通字段.而其他的成员,则都是保存在类中,即:无论对象的多少,在 ...
- JS原型与面向对象总结
ECMAScript有两种开发模式:1.函数式(过程化),2.面向对象(OOP).面向对象的语言有一个标志,那就是类的概念,而通过类可以创建任意多个具有相同属性和方法的对象.但 是,ECMAScrip ...