8.17 H – Frogger
来源:互联网 发布:ubuntu 12.04 163源 编辑:程序博客网 时间:2024/06/01 09:21
H– Frogger
Freddy Frog is sitting on a stone in the middle of alake. Suddenly he notices Fiona Frog who is sitting on another stone. He plansto visit her, but since the water is dirty and full of tourists' sunscreen, hewants to avoid swimming and instead reach her by jumping.
Unfortunately Fiona's stone is out of his jump range. Therefore Freddyconsiders to use other stones as intermediate stops and reach her by a sequenceof several small jumps.
To execute a given sequence of jumps, a frog's jump range obviously must be atleast as long as the longest jump occuring in the sequence.
The frog distance (humans also call it minimax distance) between two stonestherefore is defined as the minimum necessary jump range over all possiblepaths between the two stones.
You are given the coordinates of Freddy's stone, Fiona's stone and all otherstones in the lake. Your job is to compute the frog distance between Freddy'sand Fiona's stone.
Input
The input will contain one or more test cases. The firstline 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 #2is Fiona's stone, the other n-2 stones are unoccupied. There's a blank linefollowing 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 bythe test case number (they are numbered from 1) and y is replaced by theappropriate real number, printed to three decimals. Put a blank line after eachtest 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
题意:一直青蛙在石头上跳,输入一组石头的位置坐标,从第一个石头跳到第二个石头上,但如果两个石头相距太远的话青蛙不想跳,找到一条路径能让青蛙每次跳动距离最小,输出这条路径中最大的距离。
#include<stdio.h>#include<algorithm>using namespace std;#include<string.h>#include<math.h>struct edge {int u,v;double w;}e[1200];bool cmp(edge a,edge b){return a.w<b.w;}int m,n,l,z=0;int p[1200];double a[1200][1200],b[1200],d[1200],s[1200][5],max=1e9;void Uset(){for(int i=1;i<=n;i++){p[i]=-1;}}int find(int x){int s;for(s=x;p[s]>=0;s=p[s]);while(s!=x){int t=p[x];p[x]=s;x=t;}return s;}void Union(int u ,int v){int t1=find(u);int t2=find(v);if(t1==t2)return ;int tp=p[t1]+p[t2];if(p[t1]>p[t2]){p[t1]=t2;p[t2]=tp;}else{p[t2]=t1;p[t1]=tp;}}double min(double a,double b){if(a<b)a=b;return a;}void Kruskal(){double sum=-1;Uset();for(int i=0;i<l;i++){if(find(e[i].u)!=find(e[i].v)){Union(e[i].u,e[i].v);sum=min(e[i].w,sum);if(find(1)==find(2))break;}}z++;printf("Scenario #%d\n",z);printf("Frog Distance = %.3lf\n\n",sum);}int main(){int i,j,k;while(scanf("%d",&n),n!=0){for(i=1;i<=n;i++){scanf("%lf%lf",&s[i][1],&s[i][2]);}for(i=1;i<=n;i++){for(j=1;j<=n;j++){a[i][j]=sqrt((s[i][1]-s[j][1])*(s[i][1]-s[j][1])+(s[i][2]-s[j][2])*(s[i][2]-s[j][2]));}}l=0;for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(i!=j){e[l].u=i;e[l].v=j;e[l].w=a[i][j];l++;}//printf("%.2lf ",a[i][j]);}//printf("\n");}sort(e,e+l,cmp);/*for(i=0;i<l;i++){printf("%d %d %.2lf\n",e[i].u,e[i].v,e[i].w);}*/Kruskal();}return 0;}
- 8.17 H – Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- Frogger
- PKU2253 Frogger
- 数学&数论 知识总结
- 百度分享插件的使用
- FPN网络
- 用python写网络爬虫-爬取新浪微博评论
- 1 用python进行OpenCV实战之用OpenCV3实现图片载入、显示和储存
- 8.17 H – Frogger
- 常用正则表达式
- java集合之PriorityQueue
- 【Mybatis从0到1-001】开篇
- jsp_2
- 欢迎使用CSDN-markdown编辑器
- Windows单机配置Kafka环境
- 循环Excel指定行
- 实战丨Python黑魔法之描述符