Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 28333   Accepted: 9208

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 刚开始不会做,看了网上的提示的后说是这是Dijkstra的变种,然后还风轻云淡的说更新条件变一下就行了,结果这句话坑大了,严格来说这就不是Dijkstra!
Dijkstra维护的是两个集合,加入到S集合之中的点已经确定正确,无需再计算,但是这题不一样,就因为这点WA了十多发。关于原算法中S里的点已经正确的证明移步我前一篇博文,但是对于这题用,同样的证明方法,得不出S里的点已经正确的结论。
首先假设S中的点已经最优,而且假设即将加入S的点u没有最优,那么存在一条路径 S里的点 + 任意一点 -> u 是最优的。
那么,如果此任意点属于S,因为维护小顶堆,所以下一个确实应该讲u加入,此处无矛盾。
然后,如果此任意点不属于S,那么就存在两种情况,要么D[s]>D[u],要么D[s]<D[u],但是两种情况都可以成立,也即是说这条假设的路径是可以存在的!
所以,将算法里对S的集合维护取消就对了,只是这还算迪杰斯特拉么?稍后补上另外几种算法的代码。
 #include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
using namespace std; const int SIZE = ;
const int INF = 0x6fffffff;
int N;
int TEMP[SIZE][];
double D[SIZE];
bool S[SIZE];
struct Comp
{
bool operator ()(int & a,int & b)
{
return D[a] > D[b];
}
};
struct Node
{
int vec;
double cost;
};
vector<Node> G[SIZE]; double dis(int x_1,int y_1,int x_2,int y_2);
void dijkstra(int);
int main(void)
{
int count = ;
Node temp; while(scanf("%d",&N) && N)
{
for(int i = ;i <= N;i ++)
scanf("%d%d",&TEMP[i][],&TEMP[i][]);
for(int i = ;i <= N;i ++)
G[i].clear();
for(int i = ;i <= N;i ++)
for(int j = i + ;j <= N;j ++)
{
temp.vec = j;
temp.cost = dis(TEMP[i][],TEMP[i][],TEMP[j][],TEMP[j][]);
G[i].push_back(temp);
temp.vec = i;
G[j].push_back(temp);
} dijkstra();
printf("Scenario #%d\n",++ count);
printf("Frog Distance = %.3f\n",D[]);
puts("");
} return ;
} double dis(int x_1,int y_1,int x_2,int y_2)
{
return sqrt(pow((double)x_1 - x_2,) + pow((double)y_1 - y_2,));
} void dijkstra(int s)
{
fill(D,D + SIZE,INF);
fill(S,S + SIZE,false);
D[s] = ;
priority_queue<int,vector<int>,Comp> que;
que.push(s); while(!que.empty())
{
int cur = que.top();
que.pop();
if(cur == )
break;
/*S[cur] = true; 注释部分即为原Dij应有的部分,此题要移除,加上即WA*/ for(int i = ;i < G[cur].size();i ++)
if(/*!S[G[cur][i].vec] && */D[G[cur][i].vec] > max(G[cur][i].cost,D[cur]))
{
D[G[cur][i].vec] = max(G[cur][i].cost,D[cur]);
que.push(G[cur][i].vec);
}
}
}
#include <iostream>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std; const int INF = 0x6fffffff;
const int SIZE = ;
int N;
double D[SIZE];
struct Node
{
int vec;
double cost;
};
struct
{
int x,y;
}TEMP[SIZE];
vector<Node> G[SIZE]; double dis(int,int,int,int);
void SPFA(int);
int main(void)
{
Node temp;
int count = ; while(scanf("%d",&N) && N)
{
for(int i = ;i <= N;i ++)
scanf("%d%d",&TEMP[i].x,&TEMP[i].y);
for(int i = ;i <= N;i ++)
G[i].clear();
for(int i = ;i <= N;i ++)
for(int j = i + ;j <= N;j ++)
{
temp.vec = j;
temp.cost = dis(TEMP[i].x,TEMP[i].y,TEMP[j].x,TEMP[j].y);
G[i].push_back(temp);
temp.vec = i;
G[j].push_back(temp);
}
SPFA();
printf("Scenario #%d\n",++ count);
printf("Frog Distance = %.3f\n",sqrt(D[]));
puts("");
} return ;
} double dis(int x_1,int y_1,int x_2,int y_2)
{
return pow((double)x_1 - x_2,) + pow((double)y_1 - y_2,);
} void SPFA(int s)
{
queue<int> que;
fill(D,D + SIZE,INF);
D[s] = ;
que.push(s); while(!que.empty())
{
int cur = que.front();
que.pop(); for(int i = ;i < G[cur].size();i ++)
if(D[G[cur][i].vec] > max(D[cur],G[cur][i].cost))
{
D[G[cur][i].vec] = max(D[cur],G[cur][i].cost);
que.push(G[cur][i].vec);
}
}
}

POJ 2253 Frogger (最短路)的更多相关文章

  1. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

  2. poj 2253 Frogger(最短路 floyd)

    题目:http://poj.org/problem?id=2253 题意:给出两只青蛙的坐标A.B,和其他的n-2个坐标,任一两个坐标点间都是双向连通的.显然从A到B存在至少一条的通路,每一条通路的元 ...

  3. POJ 2253 Frogger -- 最短路变形

    这题的坑点在POJ输出double不能用%.lf而要用%.f...真是神坑. 题意:给出一个无向图,求节点1到2之间的最大边的边权的最小值. 算法:Dijkstra 题目每次选择权值最小的边进行延伸访 ...

  4. POJ 2253 Frogger ( 最短路变形 || 最小生成树 )

    题意 : 给出二维平面上 N 个点,前两个点为起点和终点,问你从起点到终点的所有路径中拥有最短两点间距是多少. 分析 : ① 考虑最小生成树中 Kruskal 算法,在建树的过程中贪心的从最小的边一个 ...

  5. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  6. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  7. POJ 2253 Frogger(dijkstra 最短路

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

  8. POJ. 2253 Frogger (Dijkstra )

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

  9. poj 2253 Frogger (dijkstra最短路)

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

随机推荐

  1. spring mvc学习(一)入门实例

    springMVC处理流程如下: 通过配置DispacherServlet拦截指定的url,让后经HanddlerMapping来决定调用我自定义的Controller,在Controller中经过业 ...

  2. C# try catch finally 执行

    try { //dosomething eg: int a = 1; int b = 2; int c = a + b; if(c>2) { return; } } catch(Exceptio ...

  3. CentOS7安装telnet服务

    CentOS7.0 telnet-server 启动的问题.解决方法:    ①.先检查CentOS7.0是否已经安装以下两个安装包:telnet-server.xinetd.命令如下:    rpm ...

  4. cocos2d-x (Android)之-那些常见的error记

    转自:http://blog.csdn.net/callchunli/article/details/8929813 (2013/9/2) build.xml:939: java.lang.Array ...

  5. Hex-Rays Decompiler Tips and tricks Volatile memory

    https://www.hex-rays.com/products/decompiler/manual/tricks.shtml First of all, read the troubleshoot ...

  6. Java数据结构之树和二叉树(2)

    从这里始将要继续进行Java数据结构的相关讲解,Are you ready?Let's go~~ Java中的数据结构模型可以分为一下几部分: 1.线性结构 2.树形结构 3.图形或者网状结构 接下来 ...

  7. jackson 解析json问题

    1.json串中有key为A,但指定转换的mybean中未定义属性A,会抛异常.处理:mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, fals ...

  8. 【M17】考虑使用缓式评估

    1.缓式评估其实就是拖延战术,直到逼不得已的时候才去计算.缓式评估的使用场景有: 2.引用计数,考虑String,String是一个内含char指针(char指针以'\0'结束)的资源管理类,正常情况 ...

  9. JBoss提供的常用的对称加密算法

    package com.test.resteasy; import java.io.File; import java.net.MalformedURLException; import java.n ...

  10. 看来是要改用Gecko的节奏,放弃Awesomium吧

    Gecko的对象模型很像微软自带的WebBrowser,Awesomium实在太难啃.