poj 2253 Frogger
2016-05-18 19:19
190 查看
迪杰斯特拉的变形版。
题目是给你一些点,求青蛙从1号点到达2号点过程中,对于每一次的跳跃,求每次跳跃跳跃最短的最长距离。和求最短路相似,不过每一次松弛的是点到点的距离。
不要再宏定义max了,wa了无数遍,血的教训。
另若输出实型的话,若是交g++或gcc编译器,将%lf改为%f,交c++编译器或c编译器的话,则直接%lf即可,又是血的教训,只见wa声一片。。。
Frogger
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 34562 Accepted: 11079
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
c++编译器AC代码
题目是给你一些点,求青蛙从1号点到达2号点过程中,对于每一次的跳跃,求每次跳跃跳跃最短的最长距离。和求最短路相似,不过每一次松弛的是点到点的距离。
不要再宏定义max了,wa了无数遍,血的教训。
另若输出实型的话,若是交g++或gcc编译器,将%lf改为%f,交c++编译器或c编译器的话,则直接%lf即可,又是血的教训,只见wa声一片。。。
Frogger
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 34562 Accepted: 11079
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
c++编译器AC代码
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; struct stu { double x,y; } a[210]; double dis[210],b[210],inf=1e9; double length(double x1,double y1,double x2,double y2) { return sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)); } int main() { int n,u,ss=0,i,j,minn; while(scanf("%d",&n)&&n) { for(i=1; i<=n; i++) scanf("%lf%lf",&a[i].x,&a[i].y),dis[i]=length(a[i].x,a[i].y,a[1].x,a[1].y); memset(b,0,sizeof(b)); b[1]=1; for(i=1; i<=n-1; i++) { minn=inf; for(j=1; j<=n; j++) if(!b[j]&&dis[j]<minn) minn=dis[j],u=j; b[u]=1; if(u==2) break; for(j=1; j<=n; j++) { if(dis[j]>max(dis[u],length(a[j].x,a[j].y,a[u].x,a[u].y))) dis[j]=max(dis[u],length(a[j].x,a[j].y,a[u].x,a[u].y)); } } printf("Scenario #%d\nFrog Distance = %.3lf\n\n",++ss,dis[2]); } }
相关文章推荐
- Structure from motion-移动三维场景重建
- Redis Brief Intro
- 不用第三变量做值交换,不用sizeof判断int字节数
- Android数据存储之Sqlite的介绍及使用
- 流的概念分类
- 回归神经网络RNN(Recurrent Neural network)
- 回归神经网络RNN(Recurrent Neural network)
- 回归神经网络RNN(Recurrent Neural network)
- 回归神经网络RNN(Recurrent Neural network)
- java异常处理学习总结
- 解决多点透视问题
- 实用小工具---显示图像点坐标和点的rgb值
- 用CTime类得到当前日期、时间、星期,格式化
- linux之文件批量重命名
- 阿里云服务器centos部署web环境的步骤详解
- PythonOpenCV:MLP用于最近邻搜索
- Nginx upstream schedule strategy
- Android 通知栏Notification的整合全面学习
- POI2014 题解
- UICollectionView reloadData不走cellForRowAtIndexPath的问题