Frogger
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 83767 | Accepted: 25363 |
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
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
Source
题意大概是求一条路径,使这条路径上的最大边最小(怎么听起来有点二分的感觉)(这个答案肯定是某一条边的长度,而且n的数据范围很小,所以不用二分做了)
n的数据范围很小可以考虑用floyd的O(n3)算法
注意:floyd三层循环最开始应该枚举松弛的中间节点!!!这样避免松弛的先后顺序产生的影响!!!
这题因为精度问题G++过不了C++能过就离谱
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <cstdlib> 5 #include <queue> 6 #include <stack> 7 #include <vector> 8 #include <iostream> 9 #include "algorithm" 10 using namespace std; 11 const int MAX=205; 12 int n,cas; 13 int xx[MAX],yy[MAX]; 14 double f[MAX][MAX]; 15 double dis(int i,int j){ 16 return sqrt((xx[i]-xx[j])*(xx[i]-xx[j])*1.0+(yy[i]-yy[j])*(yy[i]-yy[j])*1.0); 17 } 18 int main(){ 19 freopen ("frogger.in","r",stdin); 20 freopen ("frogger.out","w",stdout); 21 int i,j,k; 22 while (~scanf("%d",&n)&&n!=0){ 23 for (i=1;i<=n;i++) 24 scanf("%d%d",xx+i,yy+i); 25 memset(f,0,sizeof(f)); 26 for (i=1;i<=n;i++) 27 for (j=i+1;j<=n;j++) 28 f[i][j]=f[j][i]=dis(i,j); 29 for (k=1;k<=n;k++)//第三点最先循环 30 for (i=1;i<=n;i++) 31 for (j=1;j<=n;j++) 32 f[i][j]=min(f[i][j],max(f[i][k],f[k][j])); 33 printf("Scenario #%d\nFrog Distance = %.3lf\n\n",++cas,f[1][2]); 34 } 35 return 0; 36 }
未来是什么样,未来会发生什么,谁也不知道。
但是我知道,
起码从今天开始努力,
肯定比从明天开始努力,
要快一天实现梦想。
千里之行,始于足下! ——《那年那兔那些事儿》
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理