POJ 2387 || Til the Cows Come Home(最短路,dijkstra
来源:互联网 发布:淘宝大学在哪里进 编辑:程序博客网 时间:2024/05/01 13:28
在N*N的范围内有T条路,注意一下重边,问最短路 。
因为等下要写一题计算几何加最短路的,所以又复习了一下最短路的基础。
http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html 核心思想。
#include <cstdio>#include <cmath>#include <algorithm>using namespace std;#define FONE(i,m,n) for(int i=m;i<=n;++i)const int INF = 1<<26;const int MX = 1010;int path[MX][MX];int dp[MX],vis[MX];void dijkstra(int n){ FONE(i,1,n) { vis[i] = 0; dp[i] = path[1][i]; }//initialize int milen = 0,v; FONE(i,1,n) { milen = INF; FONE(j,1,n) if( !vis[j] && dp[j] < milen) { v = j; milen = dp[j]; }// the rest G vis[v] = 1; FONE(j,1,n)//update if( !vis[j] && dp[j] > path[v][j] + dp[v]) dp[j] = path[v][j] + dp[v]; } printf("%d\n",dp[n]);}int main(){ int t,n; while( ~scanf("%d %d",&t,&n)) { FONE(i,1,n) { FONE(j,1,n) path[i][j] = INF; path[i][i] = 0; } int from,to,len; FONE(i,1,t) { scanf("%d%d%d",&from,&to,&len); if( len < path[from][to]) path[from][to] = path[to][from] = len; } dijkstra(n); } return 0;}
0 0
- POJ 2387 Til the Cows Come Home 最短路-Dijkstra
- POJ 2387 || Til the Cows Come Home(最短路,dijkstra
- poj Til the Cows Come Home (Dijkstra最短路~)
- POJ 2387 Til the Cows Come Home (最短路+Dijkstra)
- POJ 2387-Til the Cows Come Home(最短路Dijkstra+优先队列)
- poj 2387 Til the Cows Come Home(最短路SPFA+Dijkstra)
- POJ 2387 Til the Cows Come Home(最短路dijkstra)
- POJ - 2387 Til the Cows Come Home(最短路Dijkstra模板题)
- POJ-2387Til the Cows Come Home,最短路坑题,dijkstra+队列优化
- poj 2387 Til the Cows Come Home 最短路 dijkstra算法
- POJ 2387 Til the Cows Come Home 【最短路(dijkstra)】
- POJ 2387Til the Cows Come Home(最短路)
- poj 2387 Til the Cows Come Home(最短路)
- poj 2387 Til the Cows Come Home -- 最短路dijstra
- POJ 2387 Til the Cows Come Home 最短路
- POJ 2387 Til the Cows Come Home【最短路】
- POJ 2387 Til the Cows Come Home (最短路)
- poj 2387 Til the Cows Come Home (最短路)
- 判断用户输入的是数字还是字符
- keepalived和heartbeat区别
- 安卓中如何把普通文件打包进apk并且JNI中能自己读取文件内容
- ROS 学习系列 -- RViz中移动机器人来学习 URDF,TF,base_link, map,odom和odom 主题的关系
- 疯狂的数组名
- POJ 2387 || Til the Cows Come Home(最短路,dijkstra
- TestNG 编写带有依赖的测试用例
- IOS GCD的5种队列用法和异步、同步操作
- online_judge_1081
- 第十二章 trie路由--基于Linux3.10
- 【手机游戏开发优化篇】详解手游[体积]及[运行内存]的优化篇!
- sopcls6
- 用二叉树表示树
- 欢迎使用CSDN-markdown编辑器