Frogger(弗洛伊德变形)
来源:互联网 发布:广州淘宝培训汇学好 编辑:程序博客网 时间:2024/06/06 17:40
Frogger
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other)
Total Submission(s) : 83 Accepted Submission(s) : 18
Problem 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.
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
20 03 4317 419 418 50
Sample Output
Scenario #1Frog Distance = 5.000Scenario #2Frog Distance = 1.414
Source
PKU
题意:
求一个点到一个点的最短路径中的最大值。
思路:
弗洛伊德算法稍变形即可。
代码:
#include <iostream>#include <queue>#include <algorithm>#include <cmath>#include <cstring>#include <cstdio>using namespace std;int n;double mp[202][202];struct ponit{ int x,y;}g[202];int main(){ int cas=0; while(cin>>n) { if(n==0)break; cas++; memset(g,0,sizeof(g)); for(int i=1;i<=n;i++) { int xx,yy; scanf("%d%d",&xx,&yy); g[i].x=xx;g[i].y=yy; } memset(mp,0x7f,sizeof(mp)); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { mp[i][j]=mp[j][i]=sqrt((g[i].x-g[j].x)*(g[i].x-g[j].x)+(g[i].y-g[j].y)*(g[i].y-g[j].y)); //邻接矩阵 } } for(int k=1;k<=n;k++) //floyed for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) { if(i!=j&&i!=k&&j!=k&&max(mp[i][k],mp[j][k])<mp[i][j])mp[i][j]=max(mp[i][k],mp[j][k]);//关键点 } cout<<"Scenario #"<<cas<<endl; printf("Frog Distance = %.3f\n\n",mp[1][2]); } return 0;}
我还运用了一个prim算法,测试数据对,但就是A不了、、、、醉了
求大神指出错误:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <iomanip>using namespace std;double g[505][505];int xx[505],yy[505];int cas=0;double minn[505];bool u[1005];int n,i,j;double dis(int x,int y){ return sqrt((xx[x]-xx[y])*(xx[x]-xx[y])+(yy[x]-yy[y])*(yy[x]-yy[y]));}int main(){ ios::sync_with_stdio(false); while(cin>>n,n) { memset(xx,0,sizeof(xx)); memset(yy,0,sizeof(yy)); for(i=1;i<=n;i++) scanf("%d%d",&xx[i],&yy[i]); for(i=1;i<=n;i++) for(j=1;j<=n;j++){ if(i==j){continue;} g[i][j]=g[j][i]=dis(i,j); //cout<<i<<"和"<<j<<" "<<g[i][j]<<" 222"<<endl; } memset(minn,0x7f,sizeof(minn)); minn[1]=0; memset(u,1,sizeof(u)); for(i=1;i<=n;i++) { int k=0; for(j=1;j<=n;j++) if(u[j]&&minn[j]<minn[k])k=j; u[k]=0; for(j=1;j<=n;j++) if(u[j]&&minn[j]>g[k][j]) minn[j]=g[k][j]; } double man=-1000000; for(i=1;i<=n;i++) if(man<minn[i]) man=minn[i]; cout<<"Scenario #"<<++cas<<endl; printf("Frog Distance = %.3f\n\n",man); } return 0;}真心不知道哪里错了。。。
阅读全文
1 0
- Frogger(弗洛伊德变形)
- Frogger (弗洛伊德)
- POJ-2253-Frogger(弗洛伊德 迪杰斯特拉)
- POJ 2253 Frogger(最短路变形)
- poj2253 - Frogger(最短路变形)
- POJ 2253 Frogger(dijkstra变形)
- POJ 2253 Frogger (Floyd的变形)
- POJ 2253 - Frogger(dijkstra变形)
- poj 2253 Frogger(dijkstra变形)
- POJ2253---Frogger(最短路变形)
- ACM floyd变形 Frogger
- Frogger(Floyd变形)
- Frogger(poj2253)-floyd变形
- HDU1181 变形课 【深搜、广搜、弗洛伊德(Floyd)算法】
- POJ 2253Frogger(dijk最短路变形)
- POJ 题目2253 Frogger(最短路变形)
- POJ 2253 Frogger(最短路变形,floyd算法)
- Frogger(最短路_floyd变形)
- JAVA设计模式之抽象工厂模式
- 剑指offer题62
- 【leetcode】38. Count and Say
- 安卓高手之路之图形系统【5】安卓ListView和EditText配合使用时的注意事项。
- 数据存储- tmpfs+LevelDB+SSDB
- Frogger(弗洛伊德变形)
- 安卓高手之路之图形系统(6)requestLayout的流程
- ARKit从入门到精通(7)-ARCamera介绍
- POJ 2407-Relatives (欧拉函数)
- 大人们营造的世界
- Webpack 打包优化之体积篇
- 安卓高手之路之图形系统(6)ListView继续
- buider模式的缺陷
- HDU-1754 I Hate It (线段树)(仍有BUG未改)