poj-Frogger
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
解題思路:
dijsktra最短路變形
# include<stdio.h>
# include<math.h>
# include<algorithm>
//# include<windows.h>
# include<memory.h>
using namespace std;
# define INF 123123123
struct E
{
int x,y;
}po[201];
bool vis[201];
double dis[201];
double m[201][201];
int main()
{
int t,i,j,Case=0;
while(scanf("%d",&t)!=EOF)
{
Case++;
if(t==0)
{
printf("\n");
break;
}
//初始化
memset(m,INF,sizeof(m));
for(i=0;i<t;i++)
scanf("%d%d",&po[i].x,&po[i].y);
for(i=0;i<t;i++){
for(j=i+1;j<t;j++){
m[i][j]=m[j][i]=sqrt(pow(double(po[i].x-po[j].x),2)+pow(double(po[i].y-po[j].y),2));
}
}
for(i=0;i<201;i++){
dis[i]=INF;
vis[i]=false;
}
dis[0]=0;
for(i=0;i<t;i++)//o(n^2)
{
int minV=INF,index=0;
for(j=0;j<t;j++)
{
if(vis[j]==false)
{
if(dis[j]<minV)
{
minV=dis[j];
index=j;
}
}
}
vis[index]=true;
for(j=0;j<t;j++)
{
dis[j]=min(dis[j],max(dis[index],m[index][j]));
}
}
if(Case!=1)
printf("\n");
printf("Scenario #%d\n",Case);
printf("Frog Distance = %.3lf\n",dis[1]);
}
return 0;
}
相關推薦
POJ-Frogger(最小生成樹)
Frogger 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
poj-Frogger
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.
POJ - 2253 Frogger(Floyd最短路+預處理)
最短路 pri str 之間 col ace blank scanf oid 題目鏈接:http://poj.org/problem?id=2253 題意:青蛙要從點1到點2,給出各點的坐標,如果點A到點B可以通過A->C,C->B,A到B的距離可以用A-&g
POJ #2253 Frogger 變種Dijkstra
aps 路徑 lose script lap 只需要 efi double log Description 問題描述:鏈接 思路 題目的意思是青蛙想從第一塊石頭跳到第二塊石頭,中間有許多墊腳石,求能跳到第二塊石頭的路上至少需要跳多遠。拿第二個樣例來說,頂點 1
POJ-2253 Frogger dijsktra查找間隔最小的路徑
scan main struct 路徑 can 註意 sta cst () 題目鏈接:https://cn.vjudge.net/problem/POJ-2253 題意 一只Forg需要從節點1走到節點n 現要找一條各個間隔最小的路徑 問間隔最小是多少 思路 用dijskt
POJ-2253 Frogger(最短路)
tor struct code namespace https href IV 所有 put https://vjudge.net/problem/POJ-2253 題意 公青蛙想到母青蛙那裏去,期間有許多石頭,公青蛙可以通過這些石頭跳過去。問至少要跳的最大距離,
POJ-2253-Frogger(最短路變形)
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
poj 2253 Frogger dijkstra 0ms
#include<iostream> #include<stdio.h> #include<string.h> #include<cstring> #include<algorithm> #include<st
POJ 2253 Frogger
每條通路中的最長邊(集合)的最小值 再在這個最長邊的集合裡面找最小值。 意思就是說,不僅要去找通路,而且還要找到那條最長邊所在的通路。 【坑】那麼找到的可能不是每個通路里最長的那條邊, 因此只有把每個通路里最長的邊先找出來,才能進行比較。 首先再讀懂題目意思。
Frogger POJ-2253
題目描述: Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone.
poj 2253 Frogger【最短路】
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32076
POJ 2253 Frogger (單源最短路變型 求路徑上最大邊權值的最小值)
題目連結 題目大意 輸入N(2≤N≤200)個點的座標,任意兩點可以互相到達,經過的距離為它們的歐式距離。現在從1號點到2號點有多條路徑,求這些路徑中最大邊權值的最小值。 分析 這題為單源最
POJ 2253 Frogger【最短路變形——路徑上最小的最大權】
/* 題意:給出一個無向圖,求一條1~2的路徑使得路徑上的最大邊權最小. 分析:dijkstra變形,將更新距離的過程改為取最大值即可. */ #include<stdio.h> #include<math.h> #include<string.h> #include&l
poj 2253——Frogger
ons map 開始 pre double make 思路 printf iostream 這個題一開始不知道咋做,但是大致有點意思。後來還是借鑒了題解發現可以用dijkstra,不太理解。但是在最後自己推的時候突然理解了。 dijkstra應該也算是動態規劃。我們用di
POJ 2253 Frogger ,poj3660Cow Contest(判斷絕對順序)(最短路,floyed)
技術 memset lse 關系 size using onclick second win POJ 2253 Frogger題目意思就是求所有路徑中最大路徑中的最小值。 #include<iostream> #include<cstdio&g
POJ 3518 Prime Gap(素數)
for org 篩選法求素數 lan article sizeof tar eof rim POJ 3518 Prime Gap(素數) http://poj.org/problem?id=3518 題意: 給你一個數。假設該數是素數就輸出0. 否則輸出比
POJ 2586 Y2K Accounting Bug(枚舉大水題)
lin uri ssd 數據丟失 span com reported cpp rem Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1067
poj 1182 (帶權並查集)
ios int 查找 食物 spa script ble 距離 輸出 食物鏈 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 71361 Accepted: 21131 Des
poj 2559 Largest Rectangle in a Histogram 棧
hist func opc txt class sse typedef ++ limit // poj 2559 Largest Rectangle in a Histogram 棧 // // n個矩形排在一塊,不同的高度,讓你求最大的矩形的面積(矩形緊挨在一起)
POJ 3461 kmp
desc href i++ -a spl ffi mem table art Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40168 Acce