poj_2253_Frogger
来源:互联网 发布:解题王软件下载 编辑:程序博客网 时间:2024/06/14 08:13
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 43
17 4
19 4
18 50
Sample Output
Scenario #1
Frog Distance = 5.000Scenario #2
Frog Distance = 1.414
题意:
代码:
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>using namespace std;double e[5005][5005],book[5005],dis[5005];struct node{ double x; double y;}s[5005];int main(){ int n,count=1; int i,j,k; double minx,inf=99999999; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(book,0,sizeof(book)); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i==j) e[i][j]=0; else e[i][j]=inf; } } for(i=1;i<=n;i++) scanf("%lf%lf",&s[i].x,&s[i].y); for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { double d=sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)+(s[i].y-s[j].y)*(s[i].y-s[j].y)); e[i][j]=e[j][i]=d; } } for(i=1;i<=n;i++) dis[i]=e[i][1]; book[1]=1; for(i=1;i<n;i++) { minx=inf; for(j=1;j<=n;j++) { if(book[j]==0 && dis[j]<minx) { minx=dis[j]; k=j; } } book[k]=1; if(k==2) break; for(j=1;j<=n;j++) { if(book[j]==0 && dis[k]+e[k][j]<inf) { double temp = max(e[k][j],dis[k]); dis[j]=min(temp,dis[j]); } } } printf("Scenario #%d\n",count); printf("Frog Distance = %.3f\n",dis[2]); printf("\n"); count++; } return 0;}
- poj_2253_Frogger
- hdu 5970 最大公约数
- 英译词典
- Peter的烟
- pycharm remote debug python in docker
- SQL创建函数
- poj_2253_Frogger
- Windows Server 2012 R2配置IIS搭载PHP发生HTTP500解决办法
- webgl——使用FBO实现离屏渲染
- Codeforces Round #432 (Div. 2) (Codeforces 850C) E. Arpa and a game with Mojtaba 博弈+状态压缩
- 转载:JNI 编写动态链接库 HelloNative 详细过程(也即用Java和C在Linux下动态生成并使用so文件过程)
- REDIS之内存分配MALLOC底层实现(转)
- vm的cpu通过cgroup来隔离
- java字符串分词器 StringTokenizer用法
- 2017.9.8 线性代数 失败总结