POJ 1797 Heavy Transportation
来源:互联网 发布:java工程师岗位总结 编辑:程序博客网 时间:2024/05/29 20:00
Description
Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists’ sunscreen, he wants to avoid swimming and instead reach her by jumping.
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.
【题目分析】
没什么要说的,最短路算法SPFA走起。
【代码】
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <queue>using namespace std;int h[1001],dis[1001],ne[1000001],to[1000001],w[1000001],en,inq[1001],kase;int n,m;inline void add(int a,int b,int c){ne[en]=h[a];to[en]=b;w[en]=c;h[a]=en++;}inline void SPFA(){ memset(dis,0,sizeof dis); dis[1]=0x3f3f3f3f; queue<int>q; q.push(1);inq[1]=1; while (!q.empty()) { int x=q.front();q.pop();inq[x]=0; for (int i=h[x];i>=0;i=ne[i]) { if (dis[to[i]]<min(dis[x],w[i])) { dis[to[i]]=min(dis[x],w[i]); if (!inq[to[i]]) { inq[to[i]]=1; q.push(to[i]); } } } }}int main(){ int tt; cin>>tt; while (tt--) { memset(h,-1,sizeof h);en=0; scanf("%d%d",&n,&m); for (int i=1;i<=m;++i) { int a,b,c; cin>>a>>b>>c; add(a,b,c);add(b,a,c); } SPFA(); printf("Scenario #%d:\n%d\n\n",++kase,dis[n]); }}
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- Poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ-1797-Heavy Transportation
- POJ 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- poj 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- POJ 1797 Heavy Transportation
- Array类型
- Intellij IDEA artifact 'XXXX:war exploded' has invalid extension
- 引用参数&
- 由深拷贝与浅拷贝引发的引用计数、写时拷贝技术
- C++跑程序所花时间
- POJ 1797 Heavy Transportation
- 数据结构实验之排序二:交换排序 sdut oj 3399
- Category 分类、类别 总结 - iOS
- 数据库的预备知识
- Android 的快捷键总结
- POJ 1129 - Channel Allocation
- 数据结构实验之串三:KMP应用
- svm系列之核函数
- Hadoop2.4.1环境搭建