
最短路
文章平均质量分 72
嘎达啊
无名小卒
展开
-
hdu1874
Djkstra:const int maxn = 10001;void Dijkstra(int n,int dist[maxn],int map[maxn][maxn],int pre[maxn],int s)//n个点,dist[i]表示i到源点s的最短距离,map记录图的信息;pre记录前驱,源点,终点{ int i, j, k; int min; bool原创 2013-07-09 19:16:46 · 387 阅读 · 0 评论 -
hdu 2923 Einbahnstrasse
这题说是100个地点 最多有1000个破车 说明 一个地点可能多辆破车;所以要用一个数组记录地点的编号,首先将地点映射为数字;用到isdigit(), sscanf(ch, "%d", &dis); 但是 我开100个地点 却是运行错误,难道理解错了 主要错在 没想到一个地方可能有多辆车,还有就是地点开小了;用了好久的时间才发现是这样的错误 ,,去上吊。。。。。。。#incl原创 2013-07-28 10:54:13 · 543 阅读 · 0 评论 -
最短路50道
HDU 1142http://acm.hdu.edu.cn/showproblem.php?pid=1142HDU 1217http://acm.hdu.edu.cn/showproblem.php?pid=1217HDU 1224http://acm.hdu.edu.cn/showproblem.php?pid=1224HDU 1245ht转载 2013-07-28 17:53:33 · 432 阅读 · 0 评论 -
hdu 1217 Arbitrage
和以往不同的是 条件不是加而是相乘, 所以要把 点的距离 和 没告诉点之间的距离 设为 1;因为是取大而不是取小 乘 1 不会改变值,Flody 将图中的任何距离,任何 两点 三点...的距离 包括点的距离都遍历了个遍,#include #include #include using namespace std;const int maxn = 35;double dist[原创 2013-07-27 18:04:06 · 578 阅读 · 0 评论 -
hdu1385 flody+记录路径
#include #include using namespace std;const int maxn = 1234;const int _max = 0x3f3f3f3f;int dist[maxn][maxn];int dir[maxn][maxn];int a[maxn];int n, k;void flody(){ for(int k = 1; k <= n原创 2013-07-22 10:10:02 · 505 阅读 · 0 评论 -
hdu2544
SPFA:#include #include #include #include using namespace std;const int _max = 0x3f3f3f3f;const int maxn = 111;int map[maxn][maxn];bool visit[maxn];int dist[maxn];int nodenum, edgenum;int原创 2013-07-12 21:31:47 · 434 阅读 · 0 评论 -
hdu2066
设置一个虚点;#include #include #include #include using namespace std;const int _max = 0x3f3f3f3f;const int maxn = 1111;int map[maxn][maxn];bool visit[maxn];int dist[maxn];int T, S, D;void inin原创 2013-07-15 20:16:29 · 483 阅读 · 0 评论 -
hdu2112
#include #include #include #include #include #include using namespace std;const int _max = 0x3f3f3f3f;const int maxn = 155;int way[maxn][maxn];bool visit[maxn];int dist[maxn];string start,原创 2013-07-14 14:23:04 · 545 阅读 · 0 评论 -
hdu1690
#include #include #include using namespace std;const long long _max = 999999999999LL;//加LL要不然报数据太大;const int maxn = 111;long long dist[maxn][maxn];//多个距离相加 可能爆intint a[200];int n, m;int l1,l2原创 2013-07-14 16:37:48 · 479 阅读 · 0 评论 -
Yandex.Algorithm 2011 Qualification 2 A. Double Cola
#include #include #include using namespace std;int main(){ int x; int sum = 0; scanf("%d", &x); for(int i = 0;; i++) { sum = sum+pow(2,i)*5; if(sum==x)原创 2013-07-14 14:45:00 · 536 阅读 · 0 评论 -
hdu1596
#include #include using namespace std;const int maxn = 1005;double dist[maxn][maxn];int n;void Flody(){ for(int k = 1; k <= n; k++) for(int i = 1; i <= n; i++) for(int原创 2013-07-13 11:16:31 · 553 阅读 · 0 评论 -
hdu2680
设置虚拟的点0,让他与所有的起点相连距离为0 就相当与从0点出发 找最短路;#include #include #include #include using namespace std;const int _max = 0x3f3f3f3f;const int maxn = 1000+10;int map[maxn][maxn];bool visit[maxn];int原创 2013-07-13 13:16:45 · 418 阅读 · 0 评论 -
Bellman_ford算法
Bellman-Ford 算法及其优化(一)Bellman-Ford 算法及其优化Bellman-Ford算法与另一个非常著名的Dijkstra算法一样,用于求解单源点最短路径问题。Bellman-ford算法除了可求解边权均非负的问题外,还可以解决存在负权边的问题(意义是什么,好好思考),而Dijkstra算法只能处理边权非负的问题,因此 Bellman-Ford算法的适用面要广泛一些。转载 2013-07-12 15:54:50 · 441 阅读 · 0 评论 -
hdu 2962 Trucking 二分 + Dijsktra
Dijsktra: 先找到一个与源点s相连最短路s--->k,然后通过 k 更新与源点相连的点,思路:先用二分不断逼近最高的高度下的最短路;在确定一个高度时候,就开始用Dijskstra 去找是否存在最短的路在求最短的路的时候,要判断路中的立交桥的高度要 >= 每次逼近的假设高度不断进行这样的过程 最后二分将逼近一个值,使高度最大下的一个最短路;原创 2013-07-28 21:39:53 · 475 阅读 · 0 评论