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. heartbeat在yum系发行版本的处理资料

    centos 安装包[rpm]和光盘iso文件 http://mirror.centos.org/centos/ 对应如上包的代码 http://vault.centos.org/ git.cento ...

  2. WWDC2016 观后杂感

    WWDC2016已经落幕了,我没有熬夜看看的录播. 总的来说觉得还是比较兴奋的,因为苹果将更多的APi开发出来了,可以玩出更多花样了.

  3. iOS 获取当前点击的坐标

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSSet *allTouch ...

  4. android Animation介绍

    Animation介绍: 在Android SDK介绍了2种Animation模式: 1. Tween Animation:间动画,通过对场景里的对象不断做图像变换(平移.缩放.旋转)产生动画效果,即 ...

  5. IOS 网络-深入浅出(一 )-> 三方SDWebImage

    首要我们以最为常用的UIImageView为例介绍实现原理: 1)UIImageView+WebCache:  setImageWithURL:placeholderImage:options: 先显 ...

  6. 看看C# 6.0中那些语法糖都干了些什么(中篇)

    接着上篇继续扯,其实语法糖也不是什么坏事,第一个就是吃不吃随你,第二个就是最好要知道这些糖在底层都做了些什么,不过有一点 叫眼见为实,这样才能安心的使用,一口气上五楼,不费劲. 一:字符串嵌入值 我想 ...

  7. ASP.NET MVC 5 04 - 控制器

    PS: 唉.本来这一篇前几天早就应该发了的,可是谁每月没有那么几天啊... 呵呵.开个玩笑.反正就是各种烦气,所以也就一直没上来继续发了. 年底了,摆正一下心态吧.好好干,整点钱,过年回家能跟亲朋好友 ...

  8. NFS网络共享服务部署

    10.3 NFS服务端部署环境准备 10.3.1 NFS服务部署服务器准备 服务器系统 角色 IP Centos6.7 x86_64 NFS服务器端(NFS-server) 192.168.1.14 ...

  9. python列表模拟堆栈和队列

    对列特点:先进先出.后进后出 用列表insert.pop模拟进队出队: >>> l = [] >>> l.insert(0,'p1') >>> l ...

  10. CentOS yum 源的配置与使用

    一.yum 简介 yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器.起初是由yellow dog 这一发行版的 ...