POJ 2449 Remmarguts' Date K最短路问题(单源点最短路径+A*算法)

K短路径算法 K短路径算法 头文件 #ifndef _GRAPH_H #define _GRAPH_H #include<stdio.h> #include<stdlib.h> #include<vector> #include<iostream> #include... 阅读详情

算法解释感谢Jarily  http://blog.csdn.net/jarily/article/details/8871968

/*
 *算法引入:
 *在单源点最短路径问题中,实际运用时还需知道最短路径外,次短路或者第三短路;
 *即要知道多条最短路,并排出其长度增加的顺序,即为K最短路问题;
 *
 *算法思想:
 *单源点最短路径+高级搜索A*;
 *A*算法结合了启发式方法和形式化方法;
 *启发式方法通过充分利用图给出的信息来动态地做出决定而使搜索次数大大降低;
 *形式化方法不利用图给出的信息,而仅通过数学的形式分析;
 *
 *算法通过一个估价函数f(h)来估计图中的当前点p到终点的距离,并由此决定它的搜索方向;
 *当这条路径失败时,它会尝试其他路径;
 *对于A*,估价函数=当前值+当前位置到终点的距离,即f(p)=g(p)+h(p),每次扩展估价函数值最小的一个;
 *
 *对于K短路算法来说,g(p)为当前从s到p所走的路径的长度;h(p)为点p到t的最短路的长度;
 *f(p)的意义为从s按照当前路径走到p后再走到终点t一共至少要走多远;
 *
 *为了加速计算,h(p)需要在A*搜索之前进行预处理,只要将原图的所有边反向,再从终点t做一次单源点最短路径就能得到每个点的h(p)了;
 *
 *算法步骤:
 *(1),将有向图的所有边反向,以原终点t为源点,求解t到所有点的最短距离;
 *(2),新建一个优先队列,将源点s加入到队列中;
 *(3),从优先级队列中弹出f(p)最小的点p,如果点p就是t,则计算t出队的次数;
 *如果当前为t的第k次出队,则当前路径的长度就是s到t的第k短路的长度,算法结束;
 *否则遍历与p相连的所有的边,将扩展出的到p的邻接点信息加入到优先级队列;
 *
 *算法测试:
 *PKU2449(Remmarguts' Date)
 *
 *题目大意:
 *求从s到t的第k短路的长度;
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define N 1010
#define M 100010
#define INF 1e9

typedef int type;
type dis[N];
int out[N];
bool visit[N];
struct Node
{
    int pos;
    type g,f; // g(i) 为从start到i目前已走的距离  ,  f(i)=g(i)+dis(i)
    friend bool operator<(Node a,Node b)
    {
        return a.f>b.f;
    }
};
struct
{
    int to,next;
    type c;
}edge[M<<1];
int ip;
int head1[N],head2[N];
void addedge1(int u,int v,type c)
{
    edge[ip].to=v; edge[ip].c=c; edge[ip].next=head1[u]; head1[u]=ip++;
}
void addedge2(int u,int v,type c)
{
    edge[ip].to=v; edge[ip].c=c; edge[ip].next=head2[u]; head2[u]=ip++;
}

bool spfa(int start,int end,int n) //以end为起点求i到end的最短路
{
    queue<int>q;
    memset(out,0,sizeof(out));
    memset(visit,0,sizeof(visit));
    for(int i=0;i<=n;i++) dis[i]=INF;
    q.push(start); visit[start]=1; dis[start]=0;
    int top;
    while(!q.empty())
    {
        top=q.front(); q.pop(); visit[top]=0; out[top]++;
        if(out[top]>n) return 0;
        for(int p=head2[top];p!=-1;p=edge[p].next)
        {
            if(dis[ edge[p].to ] > dis[top] + edge[p].c )
            {
                dis[edge[p].to]=dis[top]+edge[p].c;
                if(!visit[edge[p].to])
                {
                    visit[edge[p].to]=1; q.push(edge[p].to);
                }
            }
        }
    }
    if(dis[end]==INF) return 0;
    return 1;
}

int K_load(int start,int end,int k)
{
    Node top,temp;
    priority_queue<Node>q;
    int time=0;
    top.pos=start; top.g=0; top.f=dis[start]; q.push(top);
    while(!q.empty())
    {
        top=q.top(); q.pop();
        if(top.pos==end) time++;
        if(time==k) return top.f;
        for(int p=head1[top.pos];p!=-1;p=edge[p].next)
        {
            temp.pos=edge[p].to;
            temp.g=top.g+edge[p].c;
            temp.f=temp.g+dis[edge[p].to];
            q.push(temp);
        }
    }
    return -1;
}

int solve(int start,int end,int k,int n)
{
    if(!spfa(end,start,n)) return -1;
    return K_load(start,end,k);
}

int main()
{
    int n,m;
    int x,y;
    int start,end,k;
    type c;
    while(cin>>n>>m)
    {
        ip=0;
        memset(head1,-1,sizeof(head1));
        memset(head2,-1,sizeof(head2));
        while(m--)
        {
            scanf("%d%d%d",&x,&y,&c);  //c输入类型需要修改
            addedge1(x,y,c);
            addedge2(y,x,c);  //建反向边
        }
        cin>>start>>end>>k;
        if(start==end) k++;   //这题需要特殊处理
        cout<<solve(start,end,k,n)<<endl;
    }
    return 0;
}

Sumo入门和Traci接口使用 Sumo模拟仿真软件基本操作, 使用traci接口, 介绍了java和python两种语言的使用, 主要推荐使用python语言, 并给了一些简单的代码demo 阅读详情

相关推荐

浅谈K短路算法(KSP)之二(YEN .J算法求解)

对于具有n个顶点和m条边且边的权值非负的简单图(无重边和环),K短路,是指的起点s到终点t的最短路径中第k个最小的。K短路分为有限制的K短路和无限制的K短路,有限制的K短路是指求得的路径中不含有回路(路径上任何一个节点的出现次数不大于1次),无限制的K短路则对求得的路径中没有要求,这篇博客讨论后者。 本篇博客使用的图例如下图所示: 如上图所示,图中有6个顶点,9条边;即n=6,m=9; 算法主要使用了偏离路径的思想, ...

robator的专栏 6074

K最短路问题(单源点最短路径+A*算法)

/* *算法引入: *在单源点最短路径问题中,实际运用时还需知道最短路径外,次短路或者第三短路; *即要知道多条最短路,并排出其长度增加的顺序,即为K最短路问题; * *算法思想: *单源点最短路径+高级搜索A*; *A*算法结合了启发式方法和形式化方法; *启发式方法通过充分利用图给出的信息来动态地做出决定而使搜索次数大大降低; *形式化方法不利用图给出的信息,而仅通过数学的形

始往流离,终彼成章。 1万+

[POJ2449] Remmarguts' Date(k 短路 / A*)

传送门:Remmarguts' Date 题意为求源点 s 到 终点 t 的第 k 短路,可以采用启发式搜索 A* 算法来求解。 A* 算法的核心为估值函数 f(x) = g(x)+h(x) ,其中 f(x) 为当前某个点的估值,g(x) 为开始搜索时到当前点的代价,h(x) 为当前点到目标点的代价的估值,h(x) 必须小于等于实际值。而在本题中,g(x) 为到达当前点时已走的路径长度,h(x...

坤斤拷的博客 297

SUMO文档翻译索引

这里为SUMO文档的目录。

妈妈说不要造轮子 5976

DP链路训练从HPD触发到通道对齐:原理与调试实战

高速数字接口的稳定工作依赖物理层信号的精确协商,链路训练正是DisplayPort接口中确保源端与接收端在速率、摆幅和时序上达成一致的关键机制。HPD作为链路状态变化的触发信号,与通道对齐一同构成了训练流程的首尾环节。理解从时钟恢复到均衡再到多通道对齐的完整过程,有助于快速定位显示异常问题。在工程实践中,借助DPCD寄存器交互和AUX通道日志,可以系统性地排查训练失败原因。围绕链路训练全流程进行剖析,重点探讨HPD触发机制、训练图案选择、寄存器配置以及链路降级策略,为显示方案开发与调试提供工程参考。

weixin_30110543的博客 246

Win11显卡驱动安装失败的全面解决方案

Windows 11显卡驱动安装失败是一个比较常见的问题,但通过上述方法,我们可以有效地解决这一问题。方法一通过调整组策略编辑器的驱动程序安装策略,可能解决一些因签名问题导致的安装失败;而方法二则通过重装Windows 11系统,为系统提供一个全新的、干净的环境,从而可能解决更复杂的安装问题。在实际操作中,用户可以根据具体情况选择合适的方法来解决显卡驱动安装失败的问题。

nntxthml的博客 2672

POJ 2449 Remmarguts' Date 第K短路 A* + SPFA

题目大意就是给出一个图,然后给出一个起点个一个终点,求这两点间的第K短路。 本题中是可以走重复的路的,所以如果一张图中有一个环的话,无论求第几短路都是存在的。 网上大部分的方法都是用A* + 最短路的方法做的。   对于A* ,估价函数 = 当前值+当前位置到终点的距离,即 F(p)=g(p)+h(p),每次扩展估价函数值中最小的一个。对于k短路来说,g(p)为当前从s到p所走的长度

水 7588

Win10安装Nek5000

1 安装wsl 2 2 安装Nek5000 3 安装依赖项 4 安装openmpi 5 配置Nek5000 6 编译Nek5000 7 运行Nek5000算例 8 安装paraview并查看结果

weixin_43176703的博客 3463

POJ 2449 Remmarguts' Date A*算法

题目大意 给定 n个点 m条边 给定起点终点和k 求起点到终点的第k短的路径是多少 没有就输出-1 样例 Sample Input 2 2 1 2 5 2 1 4 1 2 2 Sample Output 14 思路         一个比较 直接的想法是使用优先队列BFS进行求解。优先队列(堆)中保存一些二元组(x.d...

正月看雪花的博客 1806

RK3588之内存带宽计算及达成率

本章来和大家介绍一下内存带宽的计算与达成率

文艺小少年的博客 1829

OpenAI最强编程助手Codex:下载安装、使用指南(含使用方式、提示技巧、趋势)

OpenAI最近上线了最强编程Agent——Codex,一起来看看吧!

Code_流苏:在代码中寻诗意,在实践中觅真知 1万+

poj 2449 Remmarguts' Date k短路 A*

Remmarguts' Date Time Limit:4000MS Memory Limit:65536K Total Submissions:40172 Accepted:11024 Description "Good man never makes girls wait or breaks an appointment!" said the...

KIDGIN7439的专栏 1879

《Android最全面试题-Offer直通车》目录

如今Android求职是僧多粥少,竞争非常激烈,企业招聘时要求很高,本专栏汇聚android面试各种考点,各大公司Android面试题,《Android 最全面试题》将助你全方位提升,助您脱颖而出,早日拿到满意Offer。本专栏汇聚了海量优质内容,文章数量超过100 篇。凭借过硬的质量,每月新增订阅用户数以百计,如今仅需特惠价 9.9 元,限时抢购,后续将逐步恢复原价,早订阅早开启逆袭之旅。精心筹备,整理出一系列超万字精华篇章,累计数十万的 Android 面试题深度剖析。

大模型大数据攻城狮的专栏 2881

POJ2449 Remmarguts' Date(k短路(A*优化))

POJ2449 Remmarguts’ Date 题意: 有n个节点,m条边,求任意两点间的第k短路径长度 分析: 是常规的k短路板子题 但是由于本蒟蒻有一段时间没写图论题了,wa了几发… 有几个需要注意的地方: 输入的边是有向边,我开始当作无向边做了。。。 当询问s到s的第k短路时需要特殊考虑,因为我们设置自身到自身的最短路长是0,然而图中并没有自环,所以实际上并不存在长为0的这条路径,需要排...

yudi的博客 324

SAP供应商主数据_采购视图

供应商主数据_采购视图一.视图说明    供应商的采购视图维护的是采购行为和流程相关数据,维护的组织机构是采购组织。供应商如果有采购行为(如订货方),则需要维护采购视图;如果仅为结算方可无需维护。    采购视图包含采购数据、合伙人功能等两个主要页面。各页面的转换可通过界面上的前

heng0757的专栏 1万+

极验验证码: 一点即过验证(鼠标轨迹分析)

2、第一个验证接口分析(第一个w值还原) 3、第二个验证接口(第二个w值还原)这里定位w生成跟上篇文章一样,就不展开了;主要分析tt值(鼠标轨迹)的生成逻辑

qq_49268524的博客 1019

poj2449 Remmarguts' Date A*K短路

K短路

Elemmir的博客 1089

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

POJ 2449 Remmarguts' Date A*算法

求第K短路径。在A*算法中,求最短路径时,当从优先级队列中取到目的节点时就结束了,为了求K短路径,则不结束,继续从优先级队列中取节点,直到第K次取到目的节点就是第K短路径。为了使用A*算法,首先要得到启发函数 f(n)=g(n)+h(n), 其中f(n) 是从初始点经由节点n到目标点的估价函数,g(n) 是在状态空间中从初始节点到n节点的实际代价,g(n)可以在A*算法过程中得到,h(n)是从n到目标节点最佳路径的估计代价,也就是目标节点到其他所有节点的距离,需要通过其他算法(如Dijkstra、Spfa)

mimo9527的专栏 1323

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

poj 2449 Remmarguts' Date(第K短路)

poj 2449 Remmarguts’ DateDescription“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 Remm

Loi_feather的博客 500

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ 2449Remmarguts' Date (A* 求K短路)

题目链接 题意 : 求一张有向图S->T的K短路。 思路 : 经典题目。 K短路最简单并且最暴力的方法是从起始点S爆搜下去, 把到达的x的距离d[x]不停的加入到一个优先队列中去, 最后然后每次取出最短距离节点u,然后cnt[u]++一直到到达了u = T && cnt[u] = k结束搜索。 这个方法复杂度似乎是O(M*K),对于这道题目是超时或者爆内存的 = = 。 网上看了下比较好也比

Dewey's blog 1212

poj 2449 Remmarguts' Date(K短路,A*算法)

http://poj.org/problem?id=2449 大致题意:给出一个有向图,求从起点到终点的第K短路。 K短路A*算法讲解: #include #include #include #include #include #include #include #include #include #include #define LL long

1650

POJ2449 Remmarguts' Date K短路模板 【A* + dijkstra】

一、内容 题意:给定一个有向图,求S起点到T终点的第K短路 二、思路 首先反向建图,从T点建立到各点的边,求出T终点到各点的最短距离最为估价函数,用f数组保存。 bfs将fd = 距离 + 估价值入队,每次从估价值最少的点出队,若这个点等于T点且已经被遍历过K次那么直接输出答案。 由于是求第K短路,所以当一个点被遍历了K次那么久不用再入队了,因为它只会对k+1条路有用。 由于起点和终点可能相同,...

Tizzi的博客 909

poj2449 Remmarguts' Date(K短路:A*算法)

题目链接:点击打开链接 题意描述:给定一张图,求从点s出发到点t的第k短路? 解题思路:A*算法 首先预处理使用Dijkstra求出从图中任意一点到点t的最短路径,然后使用A*算法求解即可 A*算法中g为从出发点s到当前所走过的实际距离,h为从当前点到目标点t的最短距离,每次我们扩展g+h最小的点即可 思考:本题我是用剪枝:记录一个maxdis表示第k短路的一个上界,使用

Crazy_Bear 563

POJ 2449 Remmarguts' Date【K短路问题,A*、dijkstra】

POJ 2449 Remmarguts' Datehttp://poj.org/problem?id=2449算法核心:A*、dijkstra大意:求有向图中从s到t的k短路分析:1.用dijkstra逆向计算出所有点到t的最短距离dis[i]2.建立估价函数 f(i)= g(i)+h(i) 其中g(i)为从s到i的实际距离,h(i)为从i到t的最短路dis[i]3.使用上述估计函数用...

a48634331的博客 172

POJ 2449 Remmarguts' Date A*算法求第k短路

http://poj.org/problem?id=2449 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. “Pri...

xiji333的博客 212

【解题报告】POJ 2449 Remmarguts' Date -- 有向图第k短路(有重边)

/* POJ 2449 Remmarguts' Date -- 有向图第k短路(有重边) 反向求单元点最短路(Dijkstra) 然后正向搜一遍 (用优先队列搞/A*) */ #include #include #include #include #include #include #include #include //#include using namespac

生命有一种绝对 1212
上一篇: Codeforces Round #294 (Div.2) E Shaass the Great
下一篇: POJ 2987 Firing 最大权闭合图
Veda_
博客等级 码龄14年 9粉丝 41原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值