题目链接:http://poj.org/problem?id=2449 "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts lives in his kingdom UDF – Unite…
题目链接 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom.…
题意就是要求第K短的路的长度(S->T). 对于K短路,朴素想法是bfs,使用优先队列从源点s进行bfs,当第K次遍历到T的时候,就是K短路的长度. 但是这种方法效率太低,会扩展出很多状态,所以考虑用启发式搜索A*算法. 估价函数 = 当前值 + 当前位置到终点的距离,即F(p) = G(p) + H(p). G(p): 当前从S到p所走的路径距离 H(p): 当前点p到终点T的最短路径距离   ---可以先将整个图边方向取反然后以T为源点求个最短路,用SPFA提速 F(p): 从S按照当前路径…
解题关键:k短路模板题,A*算法解决. #include<cstdio> #include<cstring> #include<algorithm> #include<cstdlib> #include<iostream> #include<cmath> #include<queue> using namespace std; typedef long long ll; ; ; const int inf=1e9; str…
  Time Limit: 4000MS   Memory Limit: 65536K Total Submissions:32863   Accepted: 8953 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a st…
http://poj.org/problem?id=2449 Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 18168   Accepted: 4984 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly tou…
K短路模板,A*+SPFA求K短路.A*中h的求法为在反图中做SPFA,求出到T点的最短路,极为估价函数h(这里不再是估价,而是准确值),然后跑A*,从S点开始(此时为最短路),然后把与S点能达到的点加入堆中,维护堆,再从堆顶取当前g值最小的点(此时为第2短路),再添加相邻的点放入堆中,依此类推······保证第k次从堆顶取到的点都是第k短路(至于为什么,自己想)其实就是A*算法,这里太啰嗦了 1 #include<queue> 2 #include<cstdio> #includ…
Remmarguts' Date http://poj.org/problem?id=2449 Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30772   Accepted: 8397 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly tou…
题目链接:http://poj.org/problem?id=2449 Time Limit: 4000MS Memory Limit: 65536K Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. &quo…
Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 25216   Accepted: 6882 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, h…
Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 33606   Accepted: 9116 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, h…
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013081425/article/details/26729375 http://poj.org/problem?id=2449 大致题意:给出一个有向图,求从起点到终点的第K短路. K短路与A*算法具体解释  学长的博客.. . 算法过程 #include <stdio.h> #include <iostream> #include <algorithm> #incl…
Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One…
题目 题意:求 点s 到 点t 的 第 k 短 路的距离: 估价函数=当前值+当前位置到终点的距离 f(n)=g(n)+h(n);     g(n)表示g当前从s到p所走的路径的长度,      h(n)'启发式函数',表示为终点t到其余一点p的路径长度: (1)将有向图的所有边反向,以原终点t为源点,求解t到所有点的最短距离;  (2)新建一个优先队列,将源点s加入到队列中;  (3)从优先级队列中弹出f(p)最小的点p,如果点p就是t,则计算t出队的次数;  如果当前为t的第k次出队,则当前…
题意:找出第k短路,输出长度,没有输出-1 思路:这题可以用A*做.A*的原理是这样,我们用一个函数:f = g + h 来表示当前点的预期步数,f代表当前点的预期步数,g代表从起点走到当前的步数,h代表从当前点走到终点的最短路,显然h可以用最短路解出.那么我们从起点开始找,每次找f最小的点,直到找到第k个这样的点. 代码: #include<queue> #include<cstring> #include<set> #include<map> #incl…
题意 : 给出一个有向图.求起点 s 到终点 t 的第 k 短路.不存在则输出 -1 #include<stdio.h> #include<string.h> #include<queue> #include<algorithm> using namespace std; const int INF = 0x3f3f3f3f; ; ; struct EDGE{ int v, nxt, w; }; struct NODE{ int pos, Cost, F;…
Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions:35025   Accepted: 9467 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he…
Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30725   Accepted: 8389 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a sto…
A* + dijkstra/spfa 第K短路的模板题,就是直接把最短路当成估价函数,保证估价函数的性质(从当前状态转移的估计值一定不大于实际值) 我们建反图从终点跑最短路,就能求出从各个点到终点的最短距离,这样就能满足估价函数的性质了 要注意一点,当起点和终点一样的时候第k短路就变成k+1短了,因为0也算一条... 话说回来为啥我用pair就MLE了呢.... #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace st…
Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he told them a story. "Prince Remmarguts lives in his kingdom UDF – United Delta of Freedom. One…
题目大意:给你一个有向图,并给你三个数s.t 和 k ,让你求从点 s 到 点 t 的第 k 短的路径.如果第 k 短路不存在,则输出“-1” ,否则,输出第 k 短路的长度. 解题思路:这道题是一道简单的启发式搜索题目.而启发式搜索中A星算法是比较好理解的.A星算法中需要用到一个估价函数:f(n) = g(n)+ h(n).其中,g(n)是当前量,h(n)是估计量,两者之和 f(n) 是估计值 .在这道题中,g(n)是从起点 s 到 点n 的已走距离,h(n)是从点n 到终点 t 的最短距离(…
第一道第K短路的题目 QAQ 拿裸的DIJKSTRA + 不断扩展的A* 给2000MS过了 题意:大意是 有N个station 要求从s点到t点 的第k短路 (不过我看题意说的好像是从t到s 可能是出题人写错了) 从这题中还真的学到了很多1.第k短路的算法 A* 还有用边表实现dij (注:以下部份资料来源于网上)所谓A*就是启发是搜索 说白了就是给搜索一个顺序使得搜索更加合理减少无谓的搜索. 如何来确定搜索的顺序?..也就是用一个值来表示 这个值为f[n]..每次搜索取f[x]最小的拓展 那…
这题一开始的思路应该是直接从源点进行BFS搜索K短路. 但这样的复杂度在点数和K的值增大后将会变得很大. 而A*算法则构造一个h(x),在进行BFS时,每次都抛出最小的h(x)从而使汇点的出队速度加快. 这题则是先进行一次Dijstra求出每个点到汇点的最短路h(x)从而在优先队列中抛出最小的f(x) A*算法就是启发式搜索,基本形式就是这样:f(x)=g(x)+h(x);其中f(x)代表在x点所需要的总代价,而g(x)代表:从源点到x点已经耗费的实际代价,h(x)代表从x到终点需要的估计代价,…
K短路裸题. #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> using namespace std; struct Edge{ int too, nxt, val; }edge[100005]; struct Odge{ int too, nxt, val; }odge[100005]; struct Node{ int idd, hfc, gfc;…
=.=好菜 #include <iostream> #include <cstdio> #include <string.h> #include <cstring> #include <queue> using namespace std; ; +; typedef long long ll; const ll INF = 1e15; int n,m,head[N],rehead[N],tot; struct node { int v,w,nex…
称号:poj 2449 Remmarguts' Date 意甲冠军:给定一个图,乞讨k短路. 算法:SPFA求最短路 + AStar 以下引用大牛的分析: 首先,为了说话方便,列出一些术语: 在启示式搜索中,对于每一个状态 x.启示函数 f(x) 一般是这种形式: f(x) = g(x) + h(x) 当中 g(x) 是从初始状态走到 x 所花的代价:h(x) 是从 x 走到目标状态所须要的代价的预计值. 相对于 h(x).另一个概念叫 h*(x),表示从 x 走到目标状态所须要的实际最小代价(…
http://poj.org/problem?id=2449 Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 30754   Accepted: 8394 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little…
现在来了解A*算法是什么 现在来解决A*求K短路问题 在一个有权图中,从起点到终点最短的路径成为最短路,第2短的路成为次短路,第3短的路成为第3短路,依此类推,第k短的路成为第k短路.那么,第k短路怎么求呢? 对于第k短路,可以想到的一个比较朴素的算法就是广度优先搜索,使用优先队列从源点s进行广搜,当第k次搜索到终点t时,所的长度即所求但是这种方法在运行过程中会产生特别多的状态,当图比较简单.k比较小时,可以一试,但是当k较大或者图中点数较多时,会面临爆栈的危险.目前使用比较多的算法是单源最短路…
第k*短路模板(单项边) #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #define Max 100005 #define inf 1<<28 using namespace std; int S,T,K,n,m; int head[Max],rehead[Max]; int num,ren…
采用A*算法的k短路模板 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cstdlib> #include <queue> using namespace std; const int MAXN=200005; int init(){ int rv=0,fh=1; char c=getchar(); whi…