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的最小值为多少. 分 ...
随机推荐
- 利用CSS背景颜色属性使父级div背景透明同时避免子级标签透明。
实现背景色透明效果的代码 实现各个浏览器中具备良好的透明特性的效果,IE中使用私有滤镜filter,高端浏览器使用CSS3中的rgba属性. 输入十六进制的颜色值以及透明度,自动在IE的过渡滤镜以及C ...
- SharePoint文档库文件夹特殊字符转义
当我们在SharePoint网站文档库中新建文件夹时包含了~ " # % & * : < > ? / \ { | }字符时(一共15个), 或者以.开头或者结束,或者包含 ...
- 通过拦截器Interceptor实现Spring MVC中Controller接口访问信息的记录
java web工程项目使用了Spring+Spring MVC+Hibernate的结构,在Controller中的方法都是用于处理前端的访问信息,Controller通过调用Service进行业务 ...
- 表单中Readonly和Disabled的区别
1.readonly是要锁定这个控件,通过在界面上无法修改他(但是通过javascript可以修改他). 2.disabled和readonly有相同的地方也是可以锁定这个控件用户不能改变他的值,但是 ...
- Hadoop分布式系统的安装部署
1.关于虚拟机的复制 新建一台虚拟机,系统为CentOS7,再克隆两台,组成一个三台机器的小集群.正常情况下一般需要五台机器(一个Name节点,一个SecondName节点,三个Data节点.) 此外 ...
- 0036 Java学习笔记-多线程-创建线程的三种方式
创建线程 创建线程的三种方式: 继承java.lang.Thread 实现java.lang.Runnable接口 实现java.util.concurrent.Callable接口 所有的线程对象都 ...
- Yii2 modal中 ajax提交表单
view: // view 代码 $form = ActiveForm::begin(['id' => $model->formName()]); // js 代码 $js = <& ...
- linux的七大运行级别及级别修改
运行级别 级别说明 0 所有进程将被终止,机器将有序的停止,关机时系统处于这个运行级别 1 单用户模式,用于系统维护,只有少数进程运行,同时所有服务也不 ...
- RabbitMq 集群搭建
实验环境: 操作系统为 Centos 7.2 IP hostName 192.168.190.132 node132 192.168.190.139 node139 192.168.190.1 ...
- ubuntu 安装 vmware 12
安装VMware Workstation 12 ubuntu15.10安装VMware Workstation12的步骤如下: 1.在 https://download3.vmware.com/sof ...