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的最小值为多少. 分 ...
随机推荐
- 下载Web微信视频
1. 用浏览器(我用Chrome)登录web微信(wx.qq.com) 2. 这个时候如果有人发视频,可以点开播放.用F12打开chrome的调试平台,查看视频源的URL(绿色框的src内容) 3. ...
- Java多线程之volatile与synchronized比较
可见性: JAVA内存模型: java为了加快程序的运行效率,对一些变量的操作是在寄存器或者CPU缓存上进行的,后面再同步到主存中 看上图,线程在运行的过程中,会从主内存里面去去变量,读到自己的空间内 ...
- Python拼接字符串的7种方法
1.直接通过+操作: s = 'Python'+','+'你好'+'!'print(s) 打印结果: Python,你好! 2.通过join()方法拼接: 将列表转换成字符串 strlist=['Py ...
- Unity编辑器 - 使用GL绘制控件
Unity编辑器 - 使用GL绘制控件 控件较为复杂时,可能造成界面卡顿,在EditorGUI中也可以灵活使用GL绘制来提升性能. 以绘制线段为例: using UnityEngine; using ...
- Spring 配置请求过滤器,编码格式设为UTF-8,避免中文乱码
<!-- 配置请求过滤器,编码格式设为UTF-8,避免中文乱码--> <filter> <filter-name>springUtf8Encoding</fi ...
- 孤荷凌寒自学python第八十三天初次接触ocr配置tesseract环境
孤荷凌寒自学python第八十三天初次接触ocr配置tesseract环境 (完整学习过程屏幕记录视频地址在文末) 学习Python我肯定不会错过图片文字的识别,当然更重要的是简单的验证码识别了,今天 ...
- leetcode个人题解——#15 3sums
class Solution { public: vector<vector<int>> threeSum(vector<int>& nums) { sor ...
- Java经典问题
1.JAVA初学者都应该搞懂的问题 对于这个系列里的问题,每个学Java的人都应该搞懂.当然,如果只是学Java玩玩就无所谓了.如果你认为自己已经超越初学者了,却不很懂这些问题,请将你自己重归初学者行 ...
- centos环境配置(nginx,node.js,mysql)
1.安装 Install GCC and Development Tools on a CentOS yum group install "Development Tools" n ...
- 4-1:实现tee命令
#include <stdio.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h& ...