Til the Cows Come Home

题目链接:

http://acm.hust.edu.cn/vjudge/contest/66569#problem/A

Description

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.

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 Input

Scenario #1

Frog Distance = 5.000

Scenario #2

Frog Distance = 1.414

题意:

给出平面上的n个坐标,两两之间可联通;

求从#1到#2点的一条路径,使得其中最大的边最小;

题解:

直接用dijkstra实现即可;

dis[i]为起点s到当前点i的路径上最小的最大边;

本质与dijkstra求最短路一致;

POJ1797:求最小边最大;

(http://www.cnblogs.com/Sunshine-tcf/p/5693985.html)

本质一样,更新时存在区别;

另外,求最大最小边时,不能把dis[s]初始化为0(即循环n-1次),否则更新失败;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define mid(a,b) ((a+b)>>1)
#define LL long long
#define maxn 250
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std; int n;
double value[maxn][maxn];
double x[maxn],y[maxn];
double dis[maxn];
int pre[maxn];
bool vis[maxn]; void dijkstra(int s) {
memset(vis, 0, sizeof(vis));
memset(pre, -1, sizeof(pre));
for(int i=1; i<=n; i++) dis[i] = inf;
dis[s] = 0; for(int i=1; i<=n; i++) {
int p;
double mindis = inf;
for(int j=1; j<=n; j++) {
if(!vis[j] && dis[j]<mindis)
mindis = dis[p=j];
}
vis[p] = 1;
for(int j=1; j<=n; j++) {
if(dis[j] > max(dis[p],value[p][j])) {
dis[j] = max(dis[p], value[p][j]);
pre[j] = p;
}
}
}
} int main(int argc, char const *argv[])
{
//IN; int ca=1;
while(scanf("%d", &n) != EOF && n)
{
memset(value, 0, sizeof(value));
for(int i=1; i<=n; i++) scanf("%lf %lf", &x[i],&y[i]);
for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++)
value[i][j] = value[j][i] = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
char tmp[10]; gets(tmp); dijkstra(1); printf("Scenario #%d\nFrog Distance = %.3f\n\n", ca++,dis[2]);
} return 0;
}

POJ 2253 Frogger (dijkstra 最大边最小)的更多相关文章

  1. poj 2253 Frogger dijkstra算法实现

    点击打开链接 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21653   Accepted: 7042 D ...

  2. POJ 2253 - Frogger - [dijkstra求最短路]

    Time Limit: 1000MS Memory Limit: 65536K Description Freddy Frog is sitting on a stone in the middle ...

  3. POJ. 2253 Frogger (Dijkstra )

    POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到2可行 ...

  4. POJ 2253 Frogger(dijkstra 最短路

    POJ 2253 Frogger Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fion ...

  5. 最短路(Floyd_Warshall) POJ 2253 Frogger

    题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...

  6. POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)

    POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...

  7. POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】

    Frogger Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Stat ...

  8. poj 2253 Frogger (dijkstra最短路)

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  9. poj 2253 Frogger 最小瓶颈路(变形的最小生成树 prim算法解决(需要很好的理解prim))

    传送门: http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

  10. POJ 2253 Frogger

    题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissi ...

随机推荐

  1. Effective C++学习笔记 条款04:确定对象被使用前已先被初始化

    一.为内置类型对象进行手工初始化,因为C++不保证初始化它们. 二.对象初始化数据成员是在进入构造函数用户编写代码前完成,要想对数据成员指定初始化值,那就必须使用初始化列表. class A { pu ...

  2. timus1004 最小环()Floyd 算法

    通过别人的数据搞了好久才成功,果然还是不够成熟 做题目还是算法不能融会贯通 大意即找出图中至少3个顶点的环,且将环中点按顺序输出 用floyd算法求最小环 因为floyd算法求最短路径是通过中间量k的 ...

  3. js风格技巧

    1.一个页面的所有js都可以写成这样,比如:   var index ={};   index.User = ****;   index.Init = function(){ $("$tes ...

  4. Mysql 临时变量的 定义 和 赋值 Set 和 Into 赋值; Swith Mysql版本 Case When的用法

    一:临时变量的定义和赋值 DECLARE spot SMALLINT; -- 分隔符的位置 DECLARE tempId VARCHAR(64); -- 循环 需要用到的临时的Cid DECLARE ...

  5. 02day1

    淘汰赛制 递推 [问题描述] 淘汰赛制是一种极其残酷的比赛制度.2^n名选手分别标号1,2,3,…,2^n-1,2^n,他们将要参加n轮的激烈角逐.每一轮中,将所有参加该轮的选手按标号从小到大排序后, ...

  6. 【Java学习笔记】数组使用

    package aaa; public class aaa { public static void main(String args[]) { int a[]={1,2,3,4}; for(int ...

  7. mysql大内存高性能优化方案

    mysql优化是一个相对来说比较重要的事情了,特别像对mysql读写比较多的网站就显得非常重要了,下面我们来介绍mysql大内存高性能优化方案 8G内存下MySQL的优化 按照下面的设置试试看:key ...

  8. OracleBulkCopy的批量数据导入

    private void button1_Click(object sender, EventArgs e) { OpenFileDialog afd = new OpenFileDialog(); ...

  9. again

    建立一个IPC连接: net use \\192.168.0.5\ipc$ "123456" /u:administrator

  10. Source Insight中文乱码

    搜索都是c++的代码,本来想下一个Vc,想了下,决定下个eclipse for C++,anyway,n次n久时间下载失败后,我接受了推荐,先下了个Source Insight来看代码.然后问题就出现 ...