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的最小值为多少. 分 ...
随机推荐
- [原创]Linux-day1
原创:转发务必注明出处http://www.cnblogs.com/0zcl/p/6077298.html 一.Linux的基本原则 由目的单一的小程序组成:组合小程序完成复杂任务 一切皆文件 尽量避 ...
- adobe air类app 接入腾讯开放平台移动游戏使用带tencent包名前缀的问题
作者:Panda Fang 出处:http://www.cnblogs.com/lonkiss/p/4209159.html 原创文章,转载请注明作者和出处,未经允许不可用于商业营利活动 ------ ...
- 常用的SQL语句
使用prepareStatement对象执行的增.删.改.查sql语句: 查: String sql = "SELECT * FROM 表名 WHERE loginId=? AND pas ...
- 我的敏捷、需求分析、UML、软件设计电子书 - 下载(持续更新中)
我将所有我的电子书汇总在一起,方便大家下载!(持续更新) 文档保存在我的网站——软件知识原创基地上(www.umlonline.org),请放心下载. 1)软件设计是怎样炼成的?(2014-4-1 发 ...
- Oracle读取excel
--解析excel,转换成table,可供查询,支持xls.xlsx --首先修改这个Type,长度改为4000. CREATE OR REPLACE TYPE XYG_PUB_DATA_UPLOAD ...
- java中数据类型的转换
数据类型的转换,分为自动转换和强制转换. 自动转换是程序执行过程中“悄然”进行的转换,不需要用户提前声明,一般是从位数低的类型向位数高的类型转换 强制转换必须在代码中声明,转换顺序不受限制 自动数据类 ...
- linux命令-文件命令
1.解压.tar文件 tar -vxf *.tar 2.把一个文件夹下的内容复制到另一个文件夹 将aaa内所有内容复制到bbb cp -a aaa/* /bbb/ * 3.复制文件时不改变文件的时间 ...
- Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- [开源].NET数据库访问框架Chloe.ORM
扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...
- [LeetCode] Spiral Matrix II 螺旋矩阵之二
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...