当前位置:网站首页>PAT甲级 1030 Travel Plan
PAT甲级 1030 Travel Plan
2022-07-03 07:34:00 【九是否非随机的称呼】
迪杰特斯拉方式,要注意距离相同时,要判断costes并保存相应的路径
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;
int main(int argc, char **argv){
int N, M, S, D, i, j, k, m, n, minmin;
cin>>N>>M>>S>>D;
int INFINF = 999999;
int cityhighway[N][N];
int costes[N][N];
memset((void *)cityhighway, INFINF, sizeof(int) * N * N);
memset((void *)costes, INFINF, sizeof(int) * N * N);
int status[N];
int way[N];
int dis[N];
int cos[N];
memset((void *)cos, INFINF, sizeof(int) * N);
memset((void *)dis, INFINF, sizeof(int) * N);
memset((void *)status, 0, sizeof(int) * N);
for(i = 0; i < M; i++){
cin>>m>>n>>k>>j;
cityhighway[m][n]=cityhighway[n][m]=k;
costes[n][m]=costes[m][n]=j;
}
dis[S] = 0;
cos[S] = 0;
way[S] = S;
status[S] = 0;
for(i = 0; i < N; i++){
minmin = 999998;
for(j = 0; j < N; j++){
if(minmin > dis[j] && status[j]==0){
minmin = dis[j];
k = j;
}
}
status[k] = 1;
for(j = 0; j < N; j++){
if((minmin + cityhighway[k][j]) < dis[j] && status[j]==0){
dis[j] = minmin + cityhighway[k][j];
cos[j] = cos[k] + costes[k][j];
way[j] = k;
}else if((minmin + cityhighway[k][j]) == dis[j] && status[j]==0){
if((cos[k] + costes[k][j]) < cos[j]){
dis[j] = minmin + cityhighway[k][j];
cos[j] = cos[k] + costes[k][j];
way[j] = k;
}
}
}
}
vector<int> pth;
k = way[D];
pth.push_back(D);
while(k!=S){
pth.push_back(k);
k = way[k];
}
pth.push_back(S);
reverse(pth.begin(), pth.end());
for(i = 0; i < pth.size(); i++) cout<<pth[i]<<" ";
cout<<dis[D]<<" "<<cos[D];
return EXIT_SUCCESS;
}边栏推荐
- Vertx's responsive redis client
- Dora (discover offer request recognition) process of obtaining IP address
- Spa single page application
- 你开发数据API最快多长时间?我1分钟就足够了
- The babbage industrial policy forum
- Web router of vertx
- 项目经验分享:实现一个昇思MindSpore 图层 IR 融合优化 pass
- Leetcode 213: 打家劫舍 II
- TCP cumulative acknowledgement and window value update
- Arduino 软串口通信 的几点体会
猜你喜欢

【开发笔记】基于机智云4G转接板GC211的设备上云APP控制

FileInputStream and fileoutputstream

【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)

技术干货|昇思MindSpore NLP模型迁移之LUKE模型——阅读理解任务

截图工具Snipaste

Collector in ES (percentile / base)

Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire

Use of generics

Inverted chain disk storage in Lucene (pfordelta)

Application of pigeon nest principle in Lucene minshouldmatchsumscorer
随机推荐
2021-07-18
Comparison of advantages and disadvantages between most complete SQL and NoSQL
Analysis of the ninth Blue Bridge Cup single chip microcomputer provincial competition
Homology policy / cross domain and cross domain solutions /web security attacks CSRF and XSS
技术干货 | AlphaFold/ RoseTTAFold开源复现(2)—AlphaFold流程分析和训练构建
Project experience sharing: Based on mindspore, the acoustic model is realized by using dfcnn and CTC loss function
Web router of vertx
The babbage industrial policy forum
Mail sending of vertx
Chapter VI - Containers
項目經驗分享:實現一個昇思MindSpore 圖層 IR 融合優化 pass
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Technical dry goods | reproduce iccv2021 best paper swing transformer with Shengsi mindspire
Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
Sent by mqtt client server of vertx
pgAdmin 4 v6.11 发布,PostgreSQL 开源图形化管理工具
Some basic operations of reflection
Map interface and method
Technical dry goods Shengsi mindspire operator parallel + heterogeneous parallel, enabling 32 card training 242 billion parameter model
Collector in ES (percentile / base)
https://github.com/ZouJiu1/PAT