(最短路 Floyd diskstra prim)Frogger --POJ--2253
题目链接:http://poj.org/problem?id=2253
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31114 | Accepted: 10027 |
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
题意:
Floyd
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; #define INF 0x3f3f3f3f
#define N 300
struct node
{
int x, y;
}; double dist[N];
double G[N][N];
int vis[N], n; void IN()
{
memset(vis, , sizeof(vis)); for(int i=; i<=n; i++)
{
dist[i]=INF;
for(int j=; j<=i; j++)
G[i][j]=G[j][i]=INF;
}
} void Floyd()
{
for(int k=; k<=n; k++)
{
for(int j=; j<=n; j++)
{
for(int i=; i<=n; i++)
{
if(G[j][i] > max(G[j][k], G[k][i]))
G[j][i] = max(G[j][k], G[k][i]);
}
}
}
} int main()
{
int i, j, t=; while(scanf("%d", &n), n)
{
double w;
node s[N];
memset(s, , sizeof(s));
IN(); for(i=; i<=n; i++)
scanf("%d%d", &s[i].x, &s[i].y); for(i=; i<n; i++)
for(j=i+; j<=n; j++)
{
w = sqrt((s[i].x-s[j].x)*(s[i].x-s[j].x)*1.0 + (s[i].y-s[j].y)*(s[i].y-s[j].y)*1.0);
G[i][j] = G[j][i]=min(G[i][j], w);
} printf("Scenario #%d\n", t++); Floyd(); printf("Frog Distance = %.3f\n\n", G[][]); }
return ;
}
dijkstra
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue> using namespace std; #define INF 0xfffffff
#define N 1100
struct node
{
int x, y;
}a[N]; int n, vis[N];
double dist[N], G[N][N]; void Dij()
{
int i, j; for(i=; i<=n; i++)
{
dist[i] = G[][i];
vis[i] = ;
}
vis[] = ; for(i=; i<n; i++)
{
int index=;
double Min=INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<Min)
{
Min = dist[j];
index = j;
}
} if(index==)
continue; vis[index] = ; for(j=; j<=n; j++)
if(!vis[j] && max(dist[index], G[index][j])<dist[j])
dist[j] = max(dist[index], G[index][j]);
}
} int main()
{
int iCase = ; while(scanf("%d", &n), n)
{
int i, j; for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
{
double d = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) );
G[i][j] = G[j][i] = d;
} Dij();
printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", dist[]);
}
return ;
}
prim
类似于最小生成树
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
const int INF = (<<)-;
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define N 1100 struct node
{
int x, y;
}a[N]; int n, m;
double dist[N], G[N][N];
int vis[N]; double prim()
{
int i, j;
double ans = -; for(i=; i<=n; i++)
dist[i] = G[][i];
dist[] = ; memset(vis, , sizeof(vis));
vis[] = ; for(i=; i<=n; i++)
{
int index = ;
double Min = INF;
for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]<=Min)
{
Min = dist[j];
index = j;
}
} if(index==) break; vis[index] = ; ans = max(ans, Min); if(index==) return ans; for(j=; j<=n; j++)
{
if(!vis[j] && dist[j]>G[index][j])
dist[j] = G[index][j];
}
} return ans;
} int main()
{
int iCase=;
while(scanf("%d", &n), n)
{
int i, j; memset(a, , sizeof(a)); for(i=; i<=n; i++)
scanf("%d%d", &a[i].x, &a[i].y); for(i=; i<=n; i++)
for(j=; j<=i; j++)
G[i][j] = G[j][i] = sqrt( (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) ); printf("Scenario #%d\n", iCase++);
printf("Frog Distance = %.3f\n\n", prim());
}
return ;
}
(最短路 Floyd diskstra prim)Frogger --POJ--2253的更多相关文章
- floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253
The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists f ...
- Frogger POJ - 2253(求两个石头之间”所有通路中最长边中“的最小边)
题意 题目主要说的是,有两只青蛙,在两个石头上,他们之间也有一些石头,一只青蛙要想到达另一只青蛙所在地方,必须跳在石头上.题目中给出了两只青蛙的初始位置,以及剩余石头的位置,问一只青蛙到达另一只青 ...
- Frogger POJ - 2253
题意 给你n个点,1为起点,2为终点,要求所有1到2所有路径中每条路径上最大值的最小值. 思路 不想打最短路 跑一边最小生成树,再扫一遍1到2的路径,取最大值即可 注意g++要用%f输出!!! 常数巨 ...
- kuangbin专题专题四 Frogger POJ - 2253
题目链接:https://vjudge.net/problem/POJ-2253 思路: 从一号到二号石头的所有路线中,每条路线中都个子选出该路线中两点通路的最长距离,并在这些选出的最长距离选出最短路 ...
- Frogger - poj 2253 (Dijkstra)
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28802 Accepted: 9353 Description Fr ...
- 最短路(Floyd_Warshall) POJ 2253 Frogger
题目传送门 /* 最短路:Floyd算法模板题 */ #include <cstdio> #include <iostream> #include <algorithm& ...
- POJ 2253 Frogger ,poj3660Cow Contest(判断绝对顺序)(最短路,floyed)
POJ 2253 Frogger题目意思就是求所有路径中最大路径中的最小值. #include<iostream> #include<cstdio> #include<s ...
- poj 2253 Frogger (最长路中的最短路)
链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...
- POJ 2253 ——Frogger——————【最短路、Dijkstra、最长边最小化】
Frogger Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Stat ...
随机推荐
- threejs纹理
纹理 纹理用来表现物体的细节.理论上可以将物体的每个细节建模出来,但是这样时间成本和性能成本都太高,因此,将物体的一些细节用纹理来表示. 图片纹理 图片纹理直接在物体表面应用图片.可以使用Textur ...
- python string tuple list dict 相互转换的方法
dict = {'name': 'Zara', 'age': 7, 'class': 'First'}# 字典转为字符串,返回:<type 'str'> {'age': 7, 'name' ...
- C#设计模式-1简单工厂模式Simple Factory)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 简单的工 ...
- Informatica_(3)组件
一.Informatica介绍Informatica PowerCenter 是Informatica公司开发的世界级的企业数据集成平台,也是业界领先的ETL工具.Informatica PowerC ...
- 简单使用DESeq2/EdgeR做差异分析
简单使用DESeq2/EdgeR做差异分析 Posted: 五月 07, 2017 Under: Transcriptomics By Kai no Comments DESeq2和EdgeR都 ...
- MySQL学习笔记-MySQL数据库优化实践[转]
最近一段时间,我们整理了一些关于Percona,Linux,Flashcache,硬件设备的优化经验,分享给大家: 硬件 1.开启BBWC RAID卡都有写cache(Battery Backed W ...
- BUG(1):一个关于指针的bug
是时候记录一下这个让我栽了两次的bug了. 具体情况如下: #include <stdio.h>#include <stdlib.h> struct app_info_t { ...
- 事务 TRANSACTION
事务是数据库中一个但单独的执行单元(Unit),他通常由高级数据库操作语言(如SQL)或编程语言(如C++.Java)编写的用户程序的执行所引起.当在数据库中更改数据成功时,在事务中更改的数据便会提交 ...
- Arithmetic Slices LT413
A sequence of number is called arithmetic if it consists of at least three elements and if the diffe ...
- base64编码是什么
首先明确一点base64 是一种编码格式.就想utf-8一样,能在电脑上表示所有字符,或者换句话说通过编码能让电脑理解你想要标识的字符(因为电脑只知道0和1 ) 就像ascII 中 0100 0001