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…
  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…
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 "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…
题目链接: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…
题目链接 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.…
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…
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…
版权声明:本文为博主原创文章.未经博主同意不得转载. 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…
Remmarguts' Date Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 33081 Accepted: 8993 Description "Good man never makes girls wait or breaks an appointment!" said the mandarin duck father. Softly touching his little ducks' head, he to…
题意 : 给出一个有向图.求起点 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;…
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…
题意就是要求第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按照当前路径…
题目 题意:求 点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…
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…
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…
题目大意:给你一个有向图,并给你三个数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 的最短距离(…
A* + dijkstra/spfa 第K短路的模板题,就是直接把最短路当成估价函数,保证估价函数的性质(从当前状态转移的估计值一定不大于实际值) 我们建反图从终点跑最短路,就能求出从各个点到终点的最短距离,这样就能满足估价函数的性质了 要注意一点,当起点和终点一样的时候第k短路就变成k+1短了,因为0也算一条... 话说回来为啥我用pair就MLE了呢.... #include <bits/stdc++.h> #define INF 0x3f3f3f3f using namespace st…
=.=好菜 #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 不会.. 百度学习.. 恩. k短路不难理解的. 结合了a_star的思想.每动一次进行一次估价,然后找最小的(此时的最短路)然后累计到k 首先我们建反向边,跑一次从汇到源的最短路,将跑出来的最短路作为估价函数h 根据f=g+h 我们将源s先走,此时实际价值g为0,估价为最短路(他们的和就是s-t的最短路) 将所有s所连的边都做相同的处理,加入到堆中(假设此时到达的点为x,那么x的g等于s到这个点的边权,因为根据最优,g+h此时是从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…
第k短路 Description 一天,HighLights实在是闲的不行,他选取了n个地点,n各地点之间共有m条路径,他想找到这m条路径组成的第k短路,你能帮助他嘛? Input 第一行三个正整数,地点的数量n(2 <= n <= 2e5),边的数量m(1 <= m <= 2e5),k(1 <= k <= min(m, 200)). 接下来m行,每行三个整数,边的一个顶点u(1<=u<=n),边的另一个顶点v(1<=v<=n),边的权值w(1&…
单源最短路 所有边权都是正数 朴素Dijkstra算法(稠密图) #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=510; int n,m; int g[N][N]; int dist[N]; bool st[N]; int dijkstra(){ memset(dist,0x3f,sizeof…
题解 (搬运一个原来博客的论文题) 抱着板题的心情去,结果有大坑 就是S == T的时候也一定要走,++K 我发现按照论文写得\(O(n \log n + m + k \ log k)\)算法没有玄学A*快,不开心啊(或者我松教水平不高啊) 论文里主要是怎么样呢,把所有边反向,从T开始求最短路,然后求一个最短路树,求法就是把新边权改成 原来的边权 + 终点最短路 - 起点最短路 如果新边权是0,那么这条边就在最短路树里,如果有很多条边边权是0就随便选一条 然后我们对于每个点走一条不同于最短路的路…
思路:d(i)表示到达节点i的最大能运输的重量,转移方程d(i) = min(d(u), limit(u, i));注意优先队列应该以重量降序排序来重载小于符号. AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm> #include <cstring> #include <utility> #include <string&…
In the age of television, not many people attend theater performances. Antique Comedians of Malidinesia are aware of this fact. They want to propagate theater and, most of all, Antique Comedies. They have printed invitation cards with all the necessa…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 题目大意:给你N个公交车站,起点,终点,各站之间的距离,求起点到终点之间的最短距离.(起点终点相同距离为0)不能到达输出-1. 说真的开始看到这个题,我想利用数字标记那些地名,再利用dijsktra算法,但不知道如何用代码实现,后来在网上看博客 才知道有这样一个头文件#include<map>,map 映射,可以有这种效果,那么这题也就so easy!了, 我的AC代码 #include&l…