frogger

POJ-2253

  • 这题的代码特别像prim求解最小生成树的代码,其实两者本来也很像。
  • 这里的d数组不再维护的起点到该点的最短距离了,而是路径中的最长距离。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
const double INF=0X3F3F3F3F;
const int maxn=201;
int n;
double map[maxn][maxn];
int x[maxn];int y[maxn];
double d[maxn];
bool vis[maxn];
void dijikstra(int s){
for(int i=1;i<=n;i++){
d[i]=map[1][i];
}
for(int i=1;i<=n;i++){
int v=-1;
double mins=INF;
for(int j=1;j<=n;j++){
if(!vis[j]&&mins>d[j]){//
v=j;
mins=d[j];
}
}
if(v==-1)
break;
vis[v]=1;
for(int j=1;j<=n;j++){
if(!vis[j]&&d[j]>max(d[v],map[v][j])){
d[j]=max(d[v],map[v][j]);
}
}
}
}
int main(){
int k=0;
while(cin>>n&&n){
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
map[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
}
dijikstra(1);
cout<<"Scenario #"<<++k<<endl;
printf("Frog Distance = %.3f\n\n",d[2]);
}
return 0;
}

POJ-2253(最短路变形+dijikstra算法+求解所有路径中所有最长边中的一个最小值)的更多相关文章

  1. Heavy Transportation POJ 1797 最短路变形

    Heavy Transportation POJ 1797 最短路变形 题意 原题链接 题意大体就是说在一个地图上,有n个城市,编号从1 2 3 ... n,m条路,每条路都有相应的承重能力,然后让你 ...

  2. 【POJ - 2253】Frogger (Floyd算法)

    -->Frogger 中文翻译 Descriptions: 湖中有n块石头,编号从1到n,有两只青蛙,Bob在1号石头上,Alice在2号石头上,Bob想去看望Alice,但由于水很脏,他想避免 ...

  3. poj 1797(最短路变形)

    题目链接:http://poj.org/problem?id=1797 思路:题目意思很简单,n个顶点,m条路,每条路上都有最大载重限制,问1->n最大载重量.其实就是一最短路的变形,定义wei ...

  4. poj 3013 最短路变形

    http://poj.org/problem?id=3013 给出n个点,m个边.给出每个点的权值,每个边的权值.在m条边中选n-1条边使这n个点成为一棵树,root=1,求这棵树的最小费用,费用=树 ...

  5. poj 1797 最短路变形dijkstra

    题意:题目大意:有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量 链接:点我 解题思路:其实这个求最大边可以近似于 ...

  6. poj 2253 最短路floyd **

    题意:有两只青蛙和若干块石头,现在已知这些东西的坐标,两只青蛙A坐标和青蛙B坐标是第一个和第二个坐标,现在A青蛙想要到B青蛙那里去,并且A青蛙可以借助任意石头的跳跃,而从A到B有若干通路,问从A到B的 ...

  7. POJ 1251 Jungle Roads(Kruskal算法求解MST)

    题目: The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money w ...

  8. POJ 1797 最短路变形所有路径最小边的最大值

    题意:卡车从路上经过,给出顶点 n , 边数 m,然后是a点到b点的权值w(a到b路段的承重),求卡车最重的重量是多少可以从上面经过. 思路:求所有路径中的最小的边的最大值.可以用迪杰斯特拉算法,只需 ...

  9. POJ 3013最短路变形....

    DES:计算输的最小费用.如果不能构成树.输出-1.每条边的费用=所有的子节点权值*这条边的权值.计算第二组样例可以知道树的费用是所有的节点的权值*到根节点的最短路径的长度. 用dij的邻接矩阵形式直 ...

随机推荐

  1. hdu5497 Inversion

    Problem Description You have a sequence {a1,a2,...,an} and you can delete a contiguous subsequence o ...

  2. Atcoder ABC155_C中有关c++ STL map的用法

    题目:https://atcoder.jp/contests/abc155/tasks/abc155_c 这道题的题意是给我们n个string,让我们统计每个string出现的次数,并输出次数最多的一 ...

  3. centos 7下安装配置Supervisor

    1.安装Supervisor centos下安装yum install supervisor 2. systemctl enable supervisord 开机自启 systemctl start ...

  4. HTML——验证码

    一.HTML5的验证码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> & ...

  5. nginx的log、upstream和server

    一.log 首先一个log格式化的例子. #配置格式main的log log_format main '$host $status [$time_local] $remote_addr [$time_ ...

  6. 【非原创】codeforces 1060E Sergey and Subway 【树上任意两点距离和】

    学习博客:戳这里 本人代码: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 con ...

  7. Leetcode 30 串联所有单词的子串 滑动窗口+map

    见注释.滑动窗口还是好用. class Solution { public: vector<int> findSubstring(string s, vector<string> ...

  8. 334A Candy Bags

    A. Candy Bags time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. codeforces 1C (非原创)

    C. Ancient Berland Circus time limit per test 2 seconds memory limit per test 64 megabytes input sta ...

  10. vue中子组件更新父组件

    当在子组件里更改了某些信息且关闭子组件后,需要父组件更新修改后的内容,该如何操作 1.$emit触发 父组件 @add="add(val)" 子组件 this.$emit('add ...