Frogger
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 39453   Accepted: 12691

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
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<cstring>
#include<algorithm>
using namespace std;
typedef __int64 LL;
const int maxn = 205;
const int INF = 0x3f3f3f3f;
struct Edge{
	int u,v,w,next;
	bool operator < (const Edge &a)const
	{
		return w > a.w;
	}
}edge[maxn*maxn<<1];

struct Point{
	int x,y;
}point[maxn];

int tot = 0,head[maxn],dis[maxn];
bool vis[maxn];

double dist(int x1,int y1,int x2,int y2)
{
	return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

void addedge(int u,int v,int w)
{
	edge[tot] = (Edge){u,v,w,head[u]
	};
	head[u] = tot++;
}

void dijkstra()
{
	priority_queue<Edge>que;
	memset(dis,INF,sizeof(dis));
	memset(vis,false,sizeof(vis));
	Edge p;
	p.v = 1;
	que.push(p);
	dis[1] = 0;
	while (!que.empty())
	{
		p = que.top();
		que.pop();
		int u = p.v;
		if (vis[u])	continue;
		vis[u] = true;
		for (int i = head[u]; ~i;i = edge[i].next)
		{
			int w = max(edge[i].w,dis[u]);
			int v = edge[i].v;
			if (dis[v] > w)
			{
				dis[v] = w;
				p.u = u,p.v = v,p.w = w;
				que.push(p);
			}
		}
	}
}

int main()
{
	//freopen("input.txt","r",stdin);
	int N,tcase = 1;
	while (~scanf("%d",&N) && N)
	{
		memset(head,-1,sizeof(head));
		tot = 0;
		for (int i = 0;i < N;i++)	scanf("%d%d",&point[i].x,&point[i].y);
		for (int i = 0;i < N;i++)
		{
			for (int j = 0;j < N;j++)
			{
				int diss = dist(point[i].x,point[i].y,point[j].x,point[j].y);
				addedge(i + 1,j + 1,diss);
				addedge(j + 1,i + 1,diss);
			}
		}
		dijkstra();
		double res = sqrt(dis[2]);
		printf("Scenario #%d\n",tcase++);
		printf("Frog Distance = %.3f\n\n",res);
	}
	return 0;
}

  

POJ 2253 Frogger(Dijkstra)的更多相关文章

  1. POJ. 2253 Frogger (Dijkstra )

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

  2. POJ 2253 Frogger(dijkstra 最短路

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

  3. poj 2253 Frogger (dijkstra最短路)

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

  4. POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)

    题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...

  5. POJ 2253 Frogger(dijkstra变形)

    http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...

  6. POJ - 2253 Frogger(Dijkstra变形题)

    题意: 题目撰写者的英语真是艰难晦涩,看了别人题解,才知道这题题意. 两个forger 一个froger 要蹦到另外一个froger处,他们的最短距离是这样定义的 : The frog distanc ...

  7. POJ 2253 Frogger (dijkstra 最大边最小)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...

  8. POJ 2253 Frogger (Dijkstra变型)

    题意:求点1到点2的路径中,权值最大的那条边,其最小值是多少. 分析:最大值最小化.可以将迪杰斯特拉模板中的松弛操作加以修改,在O(n^2)的时间内解决该问题.其中需要注意的是,dist[i]指的是: ...

  9. POJ - 2253 Frogger(最短路Dijkstra or flod)

    题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...

随机推荐

  1. iOS 应用程序生命周期

    开发应用程序都要了解其生命周期. 今天我们接触一下iOS应用程序的生命周期, iOS的入口在main.m文件: int main(int argc, char * argv[]) { @autorel ...

  2. ASP.NET MVC 5 01 - ASP.NET概述

    本篇目录: ASP.NET 概述 .NET Framework 与 ASP.NET ASP.NET MVC简介 ASP.NET的特色和优势 典型案例 ▁▃▅ ASP.NET概述 ▅▃▁ 目前开发B/S ...

  3. EF里如何定制实体的验证规则和实现IObjectWithState接口进行验证以及多个实体的同时验证

    之前的Code First系列文章已经演示了如何使用Fluent API和Data Annotation的方式配置实体的属性,比如配置Destination类的Name属性长度不大于50等.本文介绍E ...

  4. ajax 允许跨域html头设置

    "Access-Control-Allow-Origin"= "*" "Access-Control-Allow-Headers"= &qu ...

  5. 移动WEB像素相关知识

    了解移动web像素的知识,主要是为了切图时心中有数.本文主要围绕一个问题:怎样根据设备厂商提供的屏幕尺寸和物理像素得到我们切图需要的逻辑像素?围绕这个问题以iphone5为例讲解涉及到的web像素相关 ...

  6. 克隆虚机网卡出现 Device eth0 does not seem to be present, delaying initialization 错误

    错误原因    克隆的Linux系统在新的机器上运行,新服务器网卡物理地址已经改变.而/etc/udev/rules.d/70-persistent-net.rules这个文件确定了网卡和MAC地址的 ...

  7. 使用NuGet发布自己的类库包(Library Package)

    STEP 1:注册并获取API Key 首先,你需要到NuGet上注册一个新的账号,然后在My Account页面,获取一个API Key,这个过程很简单,我就不作说明了. STEP 2:下载NuGe ...

  8. 在ASP.NET Core中使用Angular2,以及与Angular2的Token base身份认证

    注:下载本文提到的完整代码示例请访问:How to authorization Angular 2 app with asp.net core web api 在ASP.NET Core中使用Angu ...

  9. 在ASP.NET Core中实现一个Token base的身份认证

    注:本文提到的代码示例下载地址> How to achieve a bearer token authentication and authorization in ASP.NET Core 在 ...

  10. quartus和modelsim中使用mif和hex文件

    .mif和.hex文件都是Quartus支持的数据文件格式,常被用作内存初始化文件.可是,M odelSim却不支持.mif文件,只支持.hex文件格式,这意味着如果你的设计采用了.mif文件 ,你的 ...