POJ 2253 Frogger(Dijkstra)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 39453 | Accepted: 12691 |
Description
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
Output
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)的更多相关文章
- POJ. 2253 Frogger (Dijkstra )
POJ. 2253 Frogger (Dijkstra ) 题意分析 首先给出n个点的坐标,其中第一个点的坐标为青蛙1的坐标,第二个点的坐标为青蛙2的坐标.给出的n个点,两两双向互通,求出由1到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 ...
- poj 2253 Frogger (dijkstra最短路)
题目链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- POJ 2253 Frogger(Dijkstra变形——最短路径最大权值)
题目链接: http://poj.org/problem?id=2253 Description Freddy Frog is sitting on a stone in the middle of ...
- POJ 2253 Frogger(dijkstra变形)
http://poj.org/problem?id=2253 题意: 有两只青蛙A和B,现在青蛙A要跳到青蛙B的石头上,中间有许多石头可以让青蛙A弹跳.给出所有石头的坐标点,求出在所有通路中青蛙需要跳 ...
- POJ - 2253 Frogger(Dijkstra变形题)
题意: 题目撰写者的英语真是艰难晦涩,看了别人题解,才知道这题题意. 两个forger 一个froger 要蹦到另外一个froger处,他们的最短距离是这样定义的 : The frog distanc ...
- POJ 2253 Frogger (dijkstra 最大边最小)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description The i ...
- POJ 2253 Frogger (Dijkstra变型)
题意:求点1到点2的路径中,权值最大的那条边,其最小值是多少. 分析:最大值最小化.可以将迪杰斯特拉模板中的松弛操作加以修改,在O(n^2)的时间内解决该问题.其中需要注意的是,dist[i]指的是: ...
- POJ - 2253 Frogger(最短路Dijkstra or flod)
题意:要从起点的石头跳到终点的石头,设The frog distance为从起点到终点的某一路径中两点间距离的最大值,问在从起点到终点的所有路径中The frog distance的最小值为多少. 分 ...
随机推荐
- BI解决方案分享:地产BI数据分析系统的建设
近几年中国地产行业发展迅猛,行业整合已成大势所趋,逐步由区域开发转变为集团化的跨地区综合开发商.然而,对于处在超常规速度发展的房地产企业来说,其面临的挑战也是超常规的.企业要在有限的资金和人力条件下, ...
- 用java单例模式实现面板切换
1.首先介绍一下什么是单例模式: java单例模式是一种常见的设计模式,那么我们先看看懒汉模式: public class Singleton_ { //设为私有方法,防止被外部类引用或实例 priv ...
- Android Weekly Notes Issue #229
Android Weekly Issue #229 October 30th, 2016 Android Weekly Issue #229 Android Weekly笔记, 本期内容包括: 性能库 ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- django 1.10 CSRF验证失败的解决过程
最近工作闲,没事自学django,感觉这个最烦的就是各版本提供的api函数经常有变化,不是取消了就是参数没有了,网上搜到的帖子也没说明用的是什么版本的django,所以经常出现搬运过来的代码解决不了问 ...
- 用SVN check out项目后第三方库丢失
曾经用Cornerstone check out 一份项目下来,但其中第三方.a库始终丢失,项目报错,研究后找到了以下解决方法: 首先,Xcode默认忽略.a 文件.所以无法提交到svn服务器,但是很 ...
- bitnami redmine版本由2.3.1升级至3.2.2过程
环境: 操作系统为ubuntu13.**版本,非长期支持版. 安装目录:/opt/redmine-2.3.1-0/ 所有者用户:root 安装过程: 1. 备份2.3.1数据库 sudo /opt/r ...
- Netty:数据处理流程
Netty作为异步的.事件驱动一个网络通信框架,使用它可以帮助我们快速开发高性能高可靠性的网络服务. 为了更好的使用Netty来解决开发中的问题,学习Netty是很有必要的. Netty现在主流有三个 ...
- Oracle ORA-07445 evaopn2()+128错误问题
Oracle ORA-07445 evaopn2()+128错误问题 问题描述 Plsql developer执行一段sql报错: 经查alert log详细报错信息为: ORA-07445: exc ...
- ASP.NET MVC Filters 4种默认过滤器的使用【附示例】
过滤器(Filters)的出现使得我们可以在ASP.NET MVC程序里更好的控制浏览器请求过来的URL,不是每个请求都会响应内容,只响应特定内容给那些有特定权限的用户,过滤器理论上有以下功能: 判断 ...