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)的更多相关文章

  1. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  2. poj2253 Frogger Dijkstra变形

    题目链接:http://poj.org/problem?id=2253 就是求所有路径的最大边权值的最小值 处理时每次找出距离当前的已选的节点的最短距离,然后更新每个未选节点的值 代码: #inclu ...

  3. poj2253 Frogger dijkstra

    题目大意: 给出n个岛的坐标,前两个坐标分别为A青蛙和B青蛙所在岛的坐标,A青蛙想到达B青蛙所在的岛,A可以从某一个岛跳到任意其它一个岛上,则A到B的每条路径都有一个跳的最远的距离Xi,求这些最远距离 ...

  4. POJ 2253 Frogger(Dijkstra)

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

  5. POJ-2253 Frogger(最短路)

    https://vjudge.net/problem/POJ-2253 题意 公青蛙想到母青蛙那里去,期间有许多石头,公青蛙可以通过这些石头跳过去.问至少要跳的最大距离,即所有路径上石头间的最大距离的 ...

  6. poj 2253 Frogger (dijkstra最短路)

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

  7. POJ2253 Frogger —— 最短路变形

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

  8. POJ 2253 Frogger(dijkstra 最短路

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

  9. poj2253 Frogger(最短路变型或者最小生成树)

    /* 题意:就是源点到终点有多条的路径,每一条路径中都有一段最大的距离! 求这些路径中最大距离的最小值! Dijkstra, Floyd, spfa都是可以的!只不过是将松弛的条件变一下就行了! 想了 ...

随机推荐

  1. 齐博cms最新SQL注入网站漏洞 可远程执行代码提权

    齐博cms整站系统,是目前建站系统用的较多的一款CMS系统,开源,免费,第三方扩展化,界面可视化的操作,使用简单,便于新手使用和第二次开发,受到许多站长们的喜欢.开发架构使用的是php语言以及mysq ...

  2. mysql5.6主主复制及keepalived 高可用

    1.实验目的 mysql服务器作为生产环境中使用最广泛的数据库软件,以其开源性,稳定性而广泛使用,但同时由于数据存储,读写频率高,极易造成数据库出错,从而给企业造成不可挽回的损失,我们除了做好数据库的 ...

  3. POJ2186 强连通分量+缩点

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 40234   Accepted: 16388 De ...

  4. sort函数

    做项目的时候,排序是一种经常要用到的操作.如果每次都自己写个冒泡之类的O(n^2)排序,不但程序容易超时,而且浪费宝贵的时间,还很有可能写错.STL里面有个sort函数,可以直接对数组排序,复杂度为n ...

  5. Microsoft Security Essentials 和 Windows Defender 离线升级包下载地址

    自从微软提供了免费的杀毒软件之后我就卸载掉了其他的杀毒软件.但是最近遇到了个小问题,我这里有一批电脑不能联网,杀毒软件的升级成了问题.在网上搜索了一番,终于找到了官方的离线升级包下载地址.放在这里备用 ...

  6. Android Stadio调试gradle 插件 || Android Stadio 远程调试 || Anroid APT调试

    有时候,自己开发了gralde插件,想调试一下.毕竟打印log 成本太高.效率太低.怎么做呢? 第一种方法: 1.执行gradlew 命令的时候,加上几个参数:-Dorg.gradle.debug=t ...

  7. php长整型完整输出

    今天调用webservice时返回一个字段是int64 长整型 原始的数值应该是 190000002101056096 而php返回时转成 1.9000000210106E+17 当传入另一个接口就报 ...

  8. [网站日志]今天早上遭遇的CPU 100%情况

    今天早上9:06左右,Windows性能监视器监测到主站的Web服务器出现了CPU 100%的情况,伴随着Requests/Sec的上升,详见下图. 上图中红色线条表示的是%Processor Tim ...

  9. Fiddler安卓抓包详细教程

    电脑端抓包一般图方便就用浏览器自带的,最近需要分析安卓一个APP的HTTP请求,尝试了wireshark(功能太强大了,然而我并不会用),tcpdump(用起来还是比较麻烦),网上搜了一下,还是使用F ...

  10. eclipse 列编辑

    ALT + SHIFT +A 进入列编辑模式,可以一次性操作多行列. 再次按住 ALT + SHIFT +A 则退出列编辑模式.