POJ2253:Frogger(改造Dijkstra)
Frogger
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 64864 | Accepted: 20127 |
题目链接:http://poj.org/problem?id=2253
Description:
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping.
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:
The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.
Output:
For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.
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
题意:
在一个二维平面内,给出一些点的坐标,问从起点到终点距离最大值最小为多少。
题解:
思路和另外一道题有类似,可以看看那道题的题解:https://www.cnblogs.com/heyuhhh/p/10352107.html
都是利用贪心的思想去做,类比一下,想想就出来了。
我就直接给代码吧~
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N = ;
int n;
int x[N],y[N],head[N],vis[N];
int tot;
double d[N];
double dis(int a,int b){
return sqrt((double)(x[a]-x[b])*(x[a]-x[b])+(double)(y[a]-y[b])*(y[a]-y[b]));
}
struct Edge{
int u,v,next;
double w;
}e[N*N<<];
struct node{
int u;
double d;
bool operator < (const node &A)const{
return d>A.d;
}
};
void adde(int u,int v,double w){
e[tot].v=v;e[tot].next=head[u];e[tot].w=w;head[u]=tot++;
}
void Dijkstra(int s){
priority_queue <node> q;
for(int i=;i<=n;i++) d[i]=INF;
memset(vis,,sizeof(vis));
node now;d[s]=;
now.d=;now.u=s;
q.push(now);
while(!q.empty()){
node cur = q.top();q.pop();
int u=cur.u;
if(vis[u]) continue ;
vis[u]=;
for(int i=head[u];i!=-;i=e[i].next){
int v=e[i].v;
if(d[v]>max(d[u],e[i].w)){
d[v]=max(d[u],e[i].w);
now.d=d[v];now.u=v;
q.push(now);
}
}
}
}
int main(){
int cnt =;
while(scanf("%d",&n)!=EOF){
if(n==) break ;
cnt++;
memset(head,-,sizeof(head));tot=;
for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==j) continue ;
adde(i,j,dis(i,j));
}
}
Dijkstra();
printf("Scenario #%d\n",cnt);
printf("Frog Distance = %.3f\n",d[]);
printf("\n");
}
return ;
}
POJ2253:Frogger(改造Dijkstra)的更多相关文章
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...
- poj2253 Frogger Dijkstra变形
题目链接:http://poj.org/problem?id=2253 就是求所有路径的最大边权值的最小值 处理时每次找出距离当前的已选的节点的最短距离,然后更新每个未选节点的值 代码: #inclu ...
- poj2253 Frogger dijkstra
题目大意: 给出n个岛的坐标,前两个坐标分别为A青蛙和B青蛙所在岛的坐标,A青蛙想到达B青蛙所在的岛,A可以从某一个岛跳到任意其它一个岛上,则A到B的每条路径都有一个跳的最远的距离Xi,求这些最远距离 ...
- POJ 2253 Frogger(Dijkstra)
传送门 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39453 Accepted: 12691 Des ...
- POJ-2253 Frogger(最短路)
https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ2253 Frogger —— 最短路变形
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger(dijkstra 最短路
POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...
- poj2253 Frogger(最短路变型或者最小生成树)
/* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...
随机推荐
- 网站apache环境S2-057漏洞 利用POC 远程执行命令漏洞复现
S2-057漏洞,于2018年8月22日被曝出,该Struts2 057漏洞存在远程执行系统的命令,尤其使用linux系统,apache环境,影响范围较大,危害性较高,如果被攻击者利用直接提权到服务器 ...
- 接口和lambda表达式笔记
接口 接口是双方,即服务提供方和想让它们的对象对服务是可用的那些类,之间约定的一种机制. 声明一个接口 public interface IntSequence{ //不提供实现,则该方法为抽象方法, ...
- Linux下启动Oracle服务和监听程序步骤
Linux下启动Oracle服务和监听程序启动和关闭步骤整理如下: 1.安装oracle: 2.创建oracle系统用户: 3./home/oracle下面的.bash_profile添加几个环境变量 ...
- js学习日记-变量的坑
js变量细节是前端面试经常遇到的问题,可见其重要程度,要想掌握这个知识点,需注意以下几点: 变量提升 所谓变量提升,就是使用了var关键字申明的变量,会提升到所在作用域的顶部.es5的作用域分为全局作 ...
- linux ----- Vim进入和退出命令
Vim进入和退出命令 本来不想写任何关于vim的文章的,无奈我今天又忘记怎么退出vim了,常用命令是ESC,然后:wq(保存并退出),:q!(不保存并强制退出),i进入vim模式.另外还有其它 ...
- ThinkPHP5 Model分层及多对多关联的建立
笔者最近入手ThinkPHP5,准备用它来实现一个学生作业管理系统.简单的说就是学生在上面交老师布置的课程作业,老师也可以发布修改作业.过程中势必会碰到学生.班级和老师之间的关系.它们之间的关系是多对 ...
- Truffle基础篇-Truffle做什么的?怎么安装?
Truffle基础篇-Truffle做什么的?怎么安装? truffle资料汇总 http://truffle.tryblockchain.org/truffle3.0-integrate-nodej ...
- jqprint导入jqgrid表格时,内容溢出的原因以及解决方法
jqprint在导入表格的时候,会将原表格的样式全部拉过来,所以说原表格(如jqgrid的表格)的内容在有滚动条的时候,必须得将宽度设置为100%(等百分比的宽度),不能设置成固定宽度,不然表格内容会 ...
- Mininet实验 动态改变转发规则
介绍 拓扑如下: 在该环境下,假设H1 ping H4,初始的路由规则是S1-S2-S5,一秒后,路由转发规则变为S1-S3-S5,再过一秒,规则变为S1-S4-S5,然后再回到最初的转发规则S1-S ...
- OO5-7次作业总结
写在最前面: 转眼间就又到了一月一次的总结时间,这次的三个作业,我个人感觉可能是最令人难受的三次作业了.不只是因为它们是多线程,更是因为它们几乎是全新的三次作业,每次的代码几乎都要重头开始. 第五次作 ...