Dijkstra算法 pat1030 Travel Plan

第10章:位同步与Gardner环路(1) 第10章(1)内容如下:一、位同步与载波同步的区别1、采样时钟相位偏差的影响2、采样时钟频率偏差的影响二、Gardner环路算法与插值方法1、插值滤波器2、Gardner误差检查算法三、Gardner环路中环路滤波器与数字振荡器设计1、环路滤波器2、数控振荡器(NCO)四、Gardner环路的可运行MATLAB代码五、参考资料六、致谢 最近搞懂了Gardner环路的一些知识,于是更新第10章——位同步。 如果你稍不留意的话,这可能是你在网上能看到的介绍Gardner环路及其MATLAB仿真最详细的一篇文章了 阅读详情

Description

A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path between his/her starting city and the destination. If such a shortest path is not unique, you are supposed to output the one with the minimum cost, which is guaranteed to be unique.

Input

Each input file contains one test case. Each case starts with a line containing 4 positive integers N, M, S, and D, where N (≤500) is the number of cities (and hence the cities are numbered from 0 to N−1); M is the number of highways; S and D are the starting and the destination cities, respectively. Then M lines follow, each provides the information of a highway, in the format:

City1 City2 Distance Cost

where the numbers are all integers no more than 500, and are separated by a space.

Output

For each test case, print in one line the cities along the shortest path from the starting point to the destination, followed by the total distance and the total cost of the path. The numbers must be separated by a space and there must be no extra space at the end of output.

Sample Input

4 5 0 3
0 1 1 20
1 3 2 30
0 3 4 10
0 2 2 20
2 3 1 20

Sample Output

0 2 3 3 40

Source

pat 1030 Travel Plan 

 

  • Dijkstra用于求单源最短路径问题(求从源点到其他各个点的最短距离),且路径的权值不能为负数(负值情况用Bellman-Ford算法)。

  • 算法核心思路:每次1.从选择槽中选出能到达的最近的未占领的点(共选n次,n为总点数),2.占领该点,3.同时计算并更新选择槽,(此过程中选择槽要么多出几个可以到达的未占领的点,要么更新能到达的未占领点更短的距离),重复1、2、 3。

  • 数据结构:vis[]来区分是否占领过,d[]来保存从源点到各个点的最短距离(选择槽所记录的值),G[][]存图(各点之间的距离)。

  • 此类问题变法往往是在最短路径的基础上再多出些其他权衡标准,也就是当有多条最短路径时,从中选出在其他标准下最优那条路径。

  • 对于这些变法题有两种解决方向,一是在上面的操作3中求最短路径的同时直接讨论其他权衡标准(如下面解法一)。二是先记录下所有的最短路径再对这些路径进行讨论(如下面解法二)。

解法一:直接Dijkstra。DFS是用来打印路径。

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXV = 500;
const int INF = 1000000000;

int n;
int G[MAXV][MAXV], cost[MAXV][MAXV], pre[MAXV];
int d[MAXV], c[MAXV];
bool vis[MAXV] = {false};

//G为距离矩阵,cost为开销矩阵,pre记录最优路径上某点的前一项,d[]记录最短距离,c[]记录最小花销。

void Dijkstra(int st){
    fill(d, d+MAXV, INF);
    fill(c, c+MAXV, INF);//要初始化为无穷大。
    for(int i = 0; i < n; i++) pre[i] = i;//初始化不能漏!
    d[st] = 0;
    c[st] = 0;
    for(int i = 0; i < n; i++){
        int min = INF, u = -1;
        for(int j = 0; j < n; j++){
            if(!vis[j] && d[j] < min){
                min = d[j];
                u = j;
            }
        }

        if(u == -1)
            return;
        vis[u] = true;

        for(int j = 0; j < n; j++){
            if(!vis[j] && G[u][j] != INF){
                if(d[u]+G[u][j] < d[j]){
                    d[j] = d[u]+G[u][j];
                    c[j] = c[u]+cost[u][j];
                    pre[j] = u;
                } else if(d[u]+G[u][j] == d[j] && c[u] + cost[u][j] < c[j]){
                    pre[j] = u;
                    c[j] = c[u] + cost[u][j];
                }
            }
        }
    }

}

void DFS(int st, int de){
    if(st == de){
        printf("%d ", st);
        return;
    }
    else{
        DFS(st, pre[de]);
        printf("%d ", de);
    }
}

int main(){
    int m, st, de;
    scanf("%d%d%d%d",&n, &m, &st, &de);
    fill(G[0], G[0]+MAXV*MAXV, INF);
    fill(cost[0], cost[0]+MAXV*MAXV, INF);
    int u, v;
    for(int i = 0; i < m; i++){
        scanf("%d%d", &u, &v);
        scanf("%d%d", &G[u][v], &cost[u][v]);
        G[v][u] = G[u][v];
        cost[v][u] = cost[u][v];
    }
    Dijkstra(st);
    DFS(st, de);
    printf("%d %d", d[de], c[de]);
    return 0;
}

解法二:Dijkstra+DFS。分开求解,更好处理复杂的多维尺度。

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

const int MAXV = 500;
const int INF = 1000000000;


bool vis[MAXV] = {false};
int n, m, st, de, G[MAXV][MAXV], cost[MAXV][MAXV];
vector<int> pre[MAXV], tempPath, path;//pre无需初始化。
int d[MAXV], optCost = INF;

//G为距离矩阵,cost为开销矩阵,pre记录最优路径上某点的前一项,
//d[]记录最短距离,optCost记录最小花销, tempPath为临时路径,path为最优路径。

void Dijkstra(int s){
    fill(d, d+MAXV, INF);
    d[s] = 0;
    for(int i = 0; i < n; i++){
        int min = INF, u = -1;
        for(int j = 0; j < n; j++){
            if(!vis[j] && d[j] < min){
                min = d[j];
                u = j;
            }
        }
        if(u == -1) return;
        vis[u] = true;
        for(int v = 0; v < n; v++){
            if(!vis[v] && G[u][v] != INF){
                if(d[v] > d[u]+G[u][v]){
                    pre[v].clear();
                    pre[v].push_back(u);
                    d[v] = d[u]+G[u][v];
                }
                else if(d[v] == d[u]+G[u][v])
                    pre[v].push_back(u);
            }
        }
    }
}


void DFS(int v){
   if(st == v){
       tempPath.push_back(v);
       int totalCost = 0;
       for(int i = tempPath.size()-1; i > 0; i--){
           int id = tempPath[i], idNext = tempPath[i-1];
           totalCost += cost[id][idNext];
       }
       if(totalCost < optCost){
           optCost = totalCost;
           path = tempPath;
       }
       tempPath.pop_back();
       return;
   }
   tempPath.push_back(v);
   for(int i = 0; i < pre[v].size(); i++){
       DFS(pre[v][i]);
   }
   tempPath.pop_back();
}

int main(){
    scanf("%d%d%d%d",&n, &m, &st, &de);
    fill(G[0], G[0]+MAXV*MAXV, INF);
    fill(cost[0], cost[0]+MAXV*MAXV, INF);
    int u, v;
    for(int i = 0; i < m; i++){
        scanf("%d%d", &u, &v);
        scanf("%d%d", &G[u][v], &cost[u][v]);
        G[v][u] = G[u][v];
        cost[v][u] = cost[u][v];
    }
    Dijkstra(st);
    DFS(de);
    for(int i = path.size()-1; i >= 0; i--){
        printf("%d ", path[i]);
    }
    printf("%d %d", d[de], optCost);
    return 0;
}

tip:

  • 有向图和无向图初始化问题;源点的初始化不能漏;
  • int最大约为2*10^9,一般设无穷大INF为10^9;
  • memset()是以字节为单位作初始化;
  • fill()对图初始化是G[0]开始而不是G;
通达信源码-主力建仓-AI投研图灵室出品 AI投研图灵室1:=3*SMA((CLOSE-LLV(LOW,75))/(HHV(HIGH,75)-LLV(LOW,75))*100,20,1)-2*SMA(SMA((CLOSE-LLV(LOW,75))/(HHV(HIGH,75)-LLV(LOW,75))*100,20,1),15,1);AI投研图灵室2W:=100-100*(HHV(HIGH,14)-CLOSE)/(HHV(HIGH,14)-LLV(LOW,14));AI投研图灵室3:=SMA(SMA(AI投研图灵室2,3,1),3,1); 阅读详情

相关推荐

28、解码清华SSVEP基准数据集:从EEG信号到深度学习模型的实战指南

本文详细解析了清华大学SSVEP基准数据集的处理与深度学习模型构建全流程。从EEG信号预处理、数据维度变换到SSVEP分类模型设计,提供了实战代码示例和关键技巧,帮助读者掌握脑机接口领域的数据处理方法与模型优化策略。

weixin_29029995的博客 176

【PAT(甲级)】1030 Travel Plan

【PAT(甲级)】1030 Travel Plan(Dijkstra+dfs)

weixin_55202895的博客 397

数据产品需求文档(PRD)怎么写?阿里P8分享的模板+5个避坑点

作用:记录文档的版本、作者、评审信息,避免“文档混乱”。填写规范字段说明示例文档名称清晰反映产品名称,如“用户行为分析平台PRD”用户行为分析平台PRD_V1.0文档版本用“版本号+日期”,如V1.0_20240301编写人数据产品经理姓名+联系方式张三(138-XXXX-XXXX)评审人员业务负责人、开发经理、数据分析师、运维负责人李四(业务)、王五(开发)、赵六(数据)、周七(运维)评审时间评审日期2024-03-05评审意见。

架构师的AI之路,分享AI应用开发架构的学习与实践。 1581

【PAT甲级】1030 Travel Plan (30分):最短路径Dijkstra/Dijkstra+DFS

1030 Travel Plan (30分) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler t...

u012161251的博客 539

基于 LSTM 的船舶轨迹预测,单步预测

基于 LSTM 的船舶轨迹预测,单步预测

fyuhao的博客 1万+

mysql数据库中使用存储过程带来的好处和示例(存储过程的概念、定义、作用等详解)

MySQL的存储过程(Stored Procedure)是一组SQL语句集合。用户通过指定的存储过程名和参数来调用并执行它。存储过程可以在数据库中预编译并存储,这样它们可以被多次调用而无需重新编写或解析SQL语句。 存储过程将复杂的SQL逻辑封装在一个可重用的单元中。多次调用存储过程,而不需要重复编写相同的SQL代码。- 通过封装,可以隐藏复杂的SQL逻辑,只向用户或应用程序提供简单的接口。MySQL的存储过程和编程语言中的函数的原理和目标是一致的:封装可重用的代码逻辑并提高代码的可维护性和可重用性。

weixin_70208651的博客 1720

1030. Travel Plan (30)

A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...

291

ESP32学习,驱动LED点阵屏,SD卡播放GIF动图

搬运就可以实现效果,如果有不足,请批评指正。下步该学一下如何文章上视频了,老是截图不方便展示效果。

u011625956的博客 1869

http://pat.zju.edu.cn/contests/pat-practise/1030

1030. Travel Plan (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the distances between

我不要写标题 841

动力学约束下的运动规划算法——Hybrid A*算法(附程序实现及详细解释)

本文主要介绍动力学约束下的运动规划算法中非常经典的Hybrid A*算法,大致分为三部分,第一部分是在传统A * 算法的基础上,对Hybrid A * 算法的原理、流程进行理论介绍。第二部分是详细分析 MotionPlanning运动规划库中Hybrid A * 算法的源码,进一步深入对Hybrid A * 算法的具体细节 进行理解。 第三部分是结合前面第一部分的理论和第二部分的详细源码,对Hybrid A * 算法的流程进行综合的概括总结。

慕羽★的博客 1万+

46、聚类算法在智能交通数据分析中的应用

本文探讨了聚类算法在智能交通数据分析中的应用,介绍了K-均值算法、K-中心点算法和基于模型的聚类算法的基本原理及特点,并结合实际交通数据讨论了其应用场景与挑战。通过聚类分析,能够从海量交通数据中发现隐藏模式,为交通管理和规划提供科学依据。文章还展示了具体的案例分析和实现流程,为未来智能交通系统的发展提供了参考。

zz67890的博客 134

PAT 1030. Travel Plan (30)

1030. Travel Plan (30) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a travele...

dengkonglou4529的博客 140

LVGL misc timer 定时器(lv_timer.c)

定时器机制是LVGL中非常重要的一项功能,它承载了LVGL的延时任务执行,周期任务执行,时序任务执行等,可以说理解定时器的设计就一定程度上理解发LVGL的任务调度机制。

Bigan(安)的博客 4733

【PAT】A1030 Travel Plan【Dijkstra算法】

A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...

elegant coder 741

深度学习工具包 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")

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

PAT 甲 1030 Travel Plan Dijkstra+DFS 算法

2022.2.13 练习 PAT 甲 1030 Travel Plan (原题链接) 题解一: #include <bits/stdc++.h> using namespace std; const int MAX_NUM=510; const int INF=0x3fffffff; int n,m,s,D; int d[MAX_NUM];//起点到各点的最短路径长度 int visit[MAX_NUM]={0};//标记是否已经访问 int G[MAX_NUM][MAX_NUM];//邻接矩

想买很多漂亮衣服但是买不起的博客 612

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

PAT Advanced 1030 Travel Plan(图,最短路径,Dijkstra算法)

链接:PAT Advanced 1030 A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to deci...

Plus Ultra! 248

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

【PAT A1030】Travel Plan——Dijkstra+DFS和Dijkstra算法复盘总结

1:Dijkstra+DFS //错误总结 //1:不需要记录最小花费,这里就是和之前的DJ的区别所在,后面专门计算最小花费 //2:d[u]要进行更新 //3:temp.pop_back();//不需要传参数进去 //4:已知tempPath,不知道怎么求花费(找到相邻的下标进行操作) //5:用cin输入的时候:不要写成书上那种简便写法: //5:scanf("%d%d",&v,&n);直接用v,n作为下标进行操作,好像是不行,要进行初始化,并且还输入不进去 #include <i

WF19980719的博客 325

PAT——A1030 Travel Plan(dijkstra算法)

题目链接: #include&lt;iostream&gt; #include&lt;set&gt; #include&lt;string&gt; #include&lt;cmath&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; #include&lt;cstdio&gt; using namespace std; const in

ZMST的博客 291

【PAT A1030】Travel Plan(Dijkstra算法)

【代码】【PAT A1030】Travel Plan(Dijkstra算法)

Honeyxuu的博客 147

【PAT】1030. Travel Plan (30)【dijkstra算法】

题目描述 A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest ...

tjj1998的博客 259

PAT 1030 Travel Plan dijkstra算法+双最短条件+保存最短路

题意: 给出一个无向图。求出起点到终点的最优路,并输出所经过的点。 最优: 距离最短,若距离相等则权重最短。 思路: 1.注意这是个无向图!! 2.用vector存储经过的点。记得起点也要存储。 //628K 94MS #include #include #include #include #include #include #include #include #include

DrawnBreak 314

PAT甲级-1030-Travel Plan(Dijkstra算法+最短路径)

A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the shortest path b...

波点兔的博客 376

PAT甲级1030 Travel Plan (30 分)DFS+Dijkstra算法的综合应用

DFS+Dijkstra算法的综合应用 思路一:只用Dijkstra算法,代码如下: #include<bits/stdc++.h> using namespace std; int Map[510][510],cost[510][510],dist[510],w[510]; int n,m,s,d; const int inf=0x3fffffff; bool vis[510]={false}; int pre[510]; int sum=0; void Dijks(int start) {

优快云_Ysu的博客 184

Dijkstra算法的改进(Dijkstra算法 + dfs)

1. 我们在学习Dijkstra算法的时候可以知道求解最短路径不可能只是简单的让我们求解出从源点到其余顶点的最短路径,更多的是根据Dijkstra算法来进行进一步的改变,从而达到我们解决问题的目的,而在我们遇到的使用Dijkstra算法求解最短路径的往往也是相应的变体形式,在原来Dijkstra算法的基础上增加若干个的条件,比如最短路径上的点权之和、边权之和或者求解出存在多条最短下最短路径的条数 ...

二哈 6206

PAT A1030 Travel Plan (30分)

PAT A1030 Travel Plan (30分) 题目 原题链接 题目大意 给出城市之间的连接关系,并给出每条边的权重,计算输出从起点到终点最短路径与最少消费 大体思路 本题是典型的dijkstra+DFS模板题目,掌握了该模板此题没有什么难度 代码 #include<stdio.h> #include<algorithm> #include<vector&gt...

qq_41706836的博客 215

PAT 10.4 A 1030 Travel Plan (30 分)(最短路径及最小花费——Dijkstra算法)

1030 Travel Plan (30 分) A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to d...

小魚兒 233
上一篇: 微信小程序巧用wx:if来控制伪元素::after::before的显示
下一篇: PAT 乙 1003 我要通过!
会悟
博客等级 码龄9年 22粉丝 36原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值