【PAT】Dijkstra+最短路径种数(★)+输出路径+卡内存

【PAT甲级复习】 专题复习一:最短路径 文章目录1 无负权边的单源最短路径——Dijkstra1.1 邻接矩阵版:适用于V不超过1000的情况,复杂度O(2V22V^22V2)。1.2 邻接表版:复杂度O(V2+EV^2 + EV2+E)1.3 优先队列优化的Dijkstra1.4 记录最短路径1.5 多个标尺如何处理1.5.1 新增边权1.5.2 新增点权1.5.3 求最短路径条数1.6 多个标尺且比较复杂:Dijkstra + DFS1.6.1 Dijkstra默写模板1.6.2 DFS遍历所有最短路径模板2 有负权边的单源最短路径——Bel 阅读详情

https://www.patest.cn/contests/pat-a-practise/1087

在求最短路径种数的时候,是这样写的:

#include<bits/stdc++.h> 
using namespace std;  
int n,m,ed,a;
string st,z,y;
map<string,int> r;
struct node{
	string a;
	int b;	
}x[205];
int w[205][205];
int path[205];
int num[205];
int happy[205];
int cost[205];
int main(){
	cin>>n>>m>>st;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			w[i][j]=100000000;
		}
	}
	x[0].a=st;
	r[st]=0;
	for(int i=1;i<n;++i){
		cin>>x[i].a>>x[i].b;
		if(x[i].a=="ROM")
			ed=i;
		r[x[i].a]=i;
	}
	while(m--){
		cin>>y>>z>>a;
		w[r[y]][r[z]]=a;
		w[r[z]][r[y]]=a;
	}
	for(int i=0;i<n;++i){
		cost[i]=100000000;
	}
	priority_queue<int> q;
	q.push(0);
	cost[0]=0;
	int costs=100000000,happys=-1,nums=100000000,sum=-1,p;
	while(!q.empty()){
		int fr=q.top();
		q.pop();
		if(fr==ed){
			if(cost[fr]<costs||
			(cost[fr]==costs&&happy[fr]>happys)||
			(cost[fr]==costs&&happy[fr]==happys&&num[fr]<nums)){
				costs=cost[fr];
				happys=happy[fr];
				nums=num[fr];
				p=fr;
			}
			if(cost[fr]<costs)
				sum=1;
			else if(cost[fr]==costs)
				sum++;
			continue;
		}
		for(int i=0;i<n;++i){
			if(cost[fr]+w[fr][i]<=cost[i]){
				cost[i]=cost[fr]+w[fr][i];
				if(happy[fr]+x[i].b>happy[i]||
				(happy[fr]+x[i].b==happy[i]&&num[fr]+1<num[i])){
					happy[i]=happy[fr]+x[i].b;
					num[i]=num[fr]+1;
					path[i]=fr;
				}
				q.push(i);
			}
		}
	}
	cout<<sum<<" "<<costs<<" "<<happys<<" "<<happys/nums<<endl;
	stack<int> st;
	st.push(ed);
	while(ed!=0){
		ed=path[ed];
		st.push(ed);
	}
	while(!st.empty()){
		cout<<x[st.top()].a;
		st.pop();
		if(st.empty())
			cout<<endl;
		else
			cout<<"->";
	}
} 
然后就因为这个【最短路径种数】和【内存超限】报错了。

修改之后是这样写的:

#include<bits/stdc++.h> 
using namespace std;  
int n,m,ed,a;
string st,z,y;
map<string,int> r;
struct node{
	string a;
	int b;	
}x[205];
int w[205][205];
int path[205];
int num[205];
int happy[205];
int cost[205];
int over[205];
int main(){
	cin>>n>>m>>st;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			w[i][j]=100000000;
		}
	}
	x[0].a=st;
	r[st]=0;
	for(int i=1;i<n;++i){
		cin>>x[i].a>>x[i].b;
		if(x[i].a=="ROM")
			ed=i;
		r[x[i].a]=i;
	}
	while(m--){
		cin>>y>>z>>a;
		w[r[y]][r[z]]=a;
		w[r[z]][r[y]]=a;
	}
	for(int i=0;i<n;++i){
		cost[i]=100000000;
	}
	priority_queue<int> q;
	q.push(0);
	cost[0]=0;
	over[0]=1;
	int costs=100000000,happys=-1,nums=100000000,sum=-1,p;
	while(!q.empty()){
		int fr=q.top();
		q.pop();
		if(fr==ed){
			if(cost[fr]<costs||
			(cost[fr]==costs&&happy[fr]>happys)||
			(cost[fr]==costs&&happy[fr]==happys&&num[fr]<nums)){
				costs=cost[fr];
				happys=happy[fr];
				nums=num[fr];
				p=fr;
			}
			if(cost[fr]<costs)
				sum=1;
			else if(cost[fr]==costs)
				sum++;
			continue;
		}
		for(int i=0;i<n;++i){
			if(cost[fr]+w[fr][i]<=cost[i]){
				if(happy[fr]+x[i].b>happy[i]||
				(happy[fr]+x[i].b==happy[i]&&num[fr]+1<num[i])){
					happy[i]=happy[fr]+x[i].b;
					num[i]=num[fr]+1;
					path[i]=fr;
				}
				if(cost[i]==cost[fr]+w[fr][i]){
					over[i]+=over[fr];
				}
				else{
					q.push(i);
					over[i]=over[fr];
					cost[i]=cost[fr]+w[fr][i];
				}
			}
		}
	}
	cout<<over[ed]<<" "<<costs<<" "<<happys<<" "<<happys/nums<<endl;
	stack<int> st;
	st.push(ed);
	while(ed!=0){
		ed=path[ed];
		st.push(ed);
	}
	while(!st.empty()){
		cout<<x[st.top()].a;
		st.pop();
		if(st.empty())
			cout<<endl;
		else
			cout<<"->";
	}
} 
一开始以为【内存超限】是因为我没有把费用相同的路径合并计算(即第一个代码),但其实不是这个原因,而是我的Dijkstra是优先队列nlogn版的……改成了n2的版本就过了。

#include<bits/stdc++.h> 
using namespace std;  
int n,m,ed,a;
string st,z,y;
map<string,int> r;
struct node{
	string a;
	int b;	
}x[205];
int w[205][205];
int path[205];
int num[205];
int happy[205];
int cost[205];
int over[205];
int main(){
	cin>>n>>m>>st;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			w[i][j]=100000000;
		}
	}
	x[0].a=st;
	r[st]=0;
	for(int i=1;i<n;++i){
		cin>>x[i].a>>x[i].b;
		if(x[i].a=="ROM")
			ed=i;
		r[x[i].a]=i;
	}
	while(m--){
		cin>>y>>z>>a;
		w[r[y]][r[z]]=a;
		w[r[z]][r[y]]=a;
	}
	for(int i=0;i<n;++i){
		cost[i]=100000000;
	}
	cost[0]=0;
	over[0]=1;
	int vis[205]={0};
	int costs=100000000,happys=-1,nums=100000000,p;
	for(int nn=0;nn<n;++nn){
		int fr;
		int minn=100000000;
		for(int i=0;i<n;++i){
			if(vis[i]==1) continue; //这步千万别忘啊!!
			if(cost[i]<minn){
				minn=cost[i];
				fr=i;
			}
		}
		vis[fr]=1; //这步千万别忘啊!!
		if(fr==ed){
			if(cost[fr]<costs||
			(cost[fr]==costs&&happy[fr]>happys)||
			(cost[fr]==costs&&happy[fr]==happys&&num[fr]<nums)){
				costs=cost[fr];
				happys=happy[fr];
				nums=num[fr];
				p=fr;
			}
			continue;
		}
		for(int i=0;i<n;++i){
			if(vis[i]==1) continue; //这步千万别忘啊!!
			if(cost[fr]+w[fr][i]<=cost[i]){
				if(cost[fr]+w[fr][i]<cost[i]||
				(cost[fr]+w[fr][i]==cost[i]&&happy[fr]+x[i].b>happy[i])||
				(cost[fr]+w[fr][i]==cost[i]&&happy[fr]+x[i].b==happy[i]&&num[fr]+1<num[i])){
					happy[i]=happy[fr]+x[i].b;
					num[i]=num[fr]+1;
					path[i]=fr;
				}
				if(cost[i]==cost[fr]+w[fr][i]){
					over[i]+=over[fr];
				}
				else{
					over[i]=over[fr];
					cost[i]=cost[fr]+w[fr][i];
				}
			}
		}
	}
	cout<<over[ed]<<" "<<costs<<" "<<happys<<" "<<happys/nums<<endl;
	stack<int> st;
	st.push(ed);
	while(ed!=0){
		ed=path[ed];
		st.push(ed);
	}
	while(!st.empty()){
		cout<<x[st.top()].a;
		st.pop();
		if(st.empty())
			cout<<endl;
		else
			cout<<"->";
	}
} 


然后再仔细一看——哎呀原来内存超限的根本原因是优先队列根本就忘了用到“优先”了!( ̄_ ̄╬
于是,最完美的版本如下:

#include<bits/stdc++.h> 
using namespace std;  
int n,m,ed,a;
string st,z,y;
map<string,int> r;
struct node{
	string a;
	int b;	
}x[205];
int w[205][205];
int path[205];
int num[205];
int happy[205];
int cost[205];
int over[205];
struct cmp{
	bool operator()(const int &t1,const int &t2){  
        return cost[t1]>cost[t2];  //从小到小=大,与数组规则相反   
   }  
}; 
int main(){
	cin>>n>>m>>st;
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			w[i][j]=100000000;
		}
	}
	x[0].a=st;
	r[st]=0;
	for(int i=1;i<n;++i){
		cin>>x[i].a>>x[i].b;
		if(x[i].a=="ROM")
			ed=i;
		r[x[i].a]=i;
	}
	while(m--){
		cin>>y>>z>>a;
		w[r[y]][r[z]]=a;
		w[r[z]][r[y]]=a;
	}
	for(int i=0;i<n;++i){
		cost[i]=100000000;
	}
	priority_queue<int,vector<int>,cmp> q;
	q.push(0);
	cost[0]=0;
	over[0]=1;
	int vis[205]={0};  //这步千万别忘啊!! 
	int costs=100000000,happys=-1,nums=100000000,p;
	while(!q.empty()){
	    int fr=q.top();
	    q.pop();
	    if(vis[fr]==1) continue;  //这步千万别忘啊!! 
	    vis[fr]=1;                //这步千万别忘啊!! 
		if(fr==ed){
			if(cost[fr]<costs||
			(cost[fr]==costs&&happy[fr]>happys)||
			(cost[fr]==costs&&happy[fr]==happys&&num[fr]<nums)){
				costs=cost[fr];
				happys=happy[fr];
				nums=num[fr];
				p=fr;
			}
			continue;
		}
		for(int i=0;i<n;++i){
			if(vis[i]==1) continue; //这步千万别忘啊!! 
			if(cost[fr]+w[fr][i]<=cost[i]){
				if(cost[fr]+w[fr][i]<cost[i]||
				(cost[fr]+w[fr][i]==cost[i]&&happy[fr]+x[i].b>happy[i])||
				(cost[fr]+w[fr][i]==cost[i]&&happy[fr]+x[i].b==happy[i]&&num[fr]+1<num[i])){
					happy[i]=happy[fr]+x[i].b;
					num[i]=num[fr]+1;
					path[i]=fr;
				}
				if(cost[i]==cost[fr]+w[fr][i]){
					over[i]+=over[fr];
				}
				else{
					q.push(i);
					over[i]=over[fr];
					cost[i]=cost[fr]+w[fr][i];
				}
			}
		}
	}
	cout<<over[ed]<<" "<<costs<<" "<<happys<<" "<<happys/nums<<endl;
	stack<int> st;
	st.push(ed);
	while(ed!=0){
		ed=path[ed];
		st.push(ed);
	}
	while(!st.empty()){
		cout<<x[st.top()].a;
		st.pop();
		if(st.empty())
			cout<<endl;
		else
			cout<<"->";
	}
} 
总结一下:考PAT还是别写什么复杂的优先队列还是前向星了,节省时间增加正确率才是王道!

另外,PAT的最短路做来做去感觉好像都差不多。比如:

https://www.patest.cn/contests/pat-a-practise/1111

#include<bits/stdc++.h> 
using namespace std;  
struct node{
	int a,b;
}x[505][505];
int dis[505];
int spd[505];
int vis[505];
int path[505];
int path2[505];
int n,m,a,b,c,d,e,st,ed;
int main(){
	cin>>n>>m; 
	for(int i=0;i<n;++i){
		for(int j=0;j<n;++j){
			x[i][j].a=x[i][j].b=100000000;
		}
	}
	while(m--){
		cin>>a>>b>>c>>d>>e;
		if(c==1)
			x[a][b]={d,e};
		else{
			x[a][b]={d,e};
			x[b][a]={d,e};
		}
	}
	cin>>st>>ed;
	int tmp=ed;
	for(int i=0;i<n;++i){
		dis[i]=100000000;
		spd[i]=100000000;
	}
	dis[st]=0;spd[st]=0;
	for(int nn=0;nn<n;++nn){
		int minn=100000000,minn2=100000000,p=-1;
		for(int i=0;i<n;++i){
			if(((dis[i]<minn)||
			(dis[i]==minn&&spd[i]<minn2))&&vis[i]==0){
				minn=dis[i];
				minn2=spd[i];
				p=i; 
			} 
		}
		vis[p]=1;
		if(p==ed)
			break;
		for(int i=0;i<n;++i){
			if(vis[i]==1) continue;
			if(dis[p]+x[p][i].a<dis[i]||
			(dis[p]+x[p][i].a==dis[i]&&spd[p]+x[p][i].b<spd[i])){
				dis[i]=dis[p]+x[p][i].a;
				spd[i]=spd[p]+x[p][i].b;
				path[i]=p;
			}
		}
	}
	int ans=dis[ed];
	for(int i=0;i<n;++i){
		dis[i]=100000000;
		spd[i]=100000000;
	}
	ed=tmp;
	dis[st]=0;spd[st]=0;
	memset(vis,0,sizeof(vis));
	for(int nn=0;nn<n;++nn){
		int minn=100000000,minn2=100000000,p=-1;
		for(int i=0;i<n;++i){
			if(((spd[i]<minn)||
			(spd[i]==minn&&dis[i]<minn2))&&vis[i]==0){
				minn=spd[i];
				minn2=dis[i];
				p=i; 
			} 
		}
		vis[p]=1;
		if(p==ed)
			break;
		for(int i=0;i<n;++i){
			if(vis[i]==1) continue;
			if(spd[p]+x[p][i].b<spd[i]||
			(spd[p]+x[p][i].b==spd[i]&&dis[p]+1<dis[i])){
				spd[i]=spd[p]+x[p][i].b;
				dis[i]=dis[p]+1;
				path2[i]=p;
			}
		}
	}
	int u=0;
	while(ed!=st){
		if(path[ed]!=path2[ed]){
			u=1;
			break;
		}
		ed=path[ed];
	}
	ed=tmp;
	stack<int> stk;
	if(u==0){
		cout<<"Distance = "<<ans<<"; Time = "<<spd[ed]<<": ";
		stk.push(ed);
		while(ed!=st){
			ed=path[ed];
			stk.push(ed);
		}
		while(!stk.empty()){
			cout<<stk.top();
			stk.pop();
			if(!stk.empty())
				cout<<" -> ";
			else
				cout<<endl;
		}
		return 0;
	}
	cout<<"Distance = "<<ans<<": ";
	stk.push(ed);
	while(ed!=st){
		ed=path[ed];
		stk.push(ed);
	}
	while(!stk.empty()){
		cout<<stk.top();
		stk.pop();
		if(!stk.empty())
			cout<<" -> ";
		else
			cout<<endl;
	}
	ed=tmp;
	cout<<"Time = "<<spd[ed]<<": ";
	stk.push(ed);
	while(ed!=st){
		ed=path2[ed];
		stk.push(ed);
	}
	while(!stk.empty()){
		cout<<stk.top();
		stk.pop();
		if(!stk.empty())
			cout<<" -> ";
		else
			cout<<endl;
	}
}
再比如:

https://www.patest.cn/contests/gplt/L2-001

#include<bits/stdc++.h>
#define ll long long
using namespace std; //
struct EDGE{
    int u,v,w,next;
}edge[500*500*2+5];
int head[500*500+5],pp;
void init(){
	pp=0;
	memset(head,0,sizeof(head));
}
void add(int u,int v,int w){
    edge[++pp]=(EDGE){u,v,w,head[u]};
    head[u]=pp;
}
int n,m,a,b,c,d,e;
int x[505];
int vis[505];
int dis[505];
int cost[505];
int path[505];
int times[505];
struct cmp{  
   bool operator()(const int &t1,const int &t2){ 
   		if(dis[t1]!=dis[t2]) 
        	return dis[t1]>dis[t2];
        return cost[t1]<cost[t2];
   }  
};  
int main(){
	cin>>n>>m>>a>>b;
	init();
	for(int i=0;i<n;++i)
		cin>>x[i];
	while(m--){
		cin>>c>>d>>e;
		add(c,d,e);
		add(d,c,e);
	}
	for(int i=0;i<n;++i)
		dis[i]=100000000;
	priority_queue<int,vector<int>,cmp> q;
	q.push(a);
	dis[a]=0;
	cost[a]=x[a];
	times[a]=1;
	while(!q.empty()){
		int u=q.top();
		q.pop();
		if(vis[u]==1) continue;
		vis[u]=1;
		for(int i=head[u];i;i=edge[i].next){
			int v=edge[i].v;
			int w=edge[i].w;
			if(vis[v]==1) continue;
			if(dis[u]+w<dis[v]) times[v]=times[u];
			else if(dis[u]+w==dis[v]) times[v]+=times[u]; 
			if(dis[u]+w<dis[v]){
				dis[v]=dis[u]+w;
				cost[v]=cost[u]+x[v];
				q.push(v);
				path[v]=u;
			}
			else if(dis[u]+w==dis[v]&&cost[u]+x[v]>cost[v]){
				cost[v]=cost[u]+x[v];
				q.push(v);
				path[v]=u;
			}
		}
	}
	cout<<times[b]<<" "<<cost[b]<<endl;
	stack<int> st;
	int tmp=b;
	while(path[b]!=a){
		st.push(path[b]);
		b=path[b];
	}
	cout<<a;
	while(!st.empty()){
		cout<<" "<<st.top();
		st.pop();
	}
	if(b!=a)
		cout<<" "<<tmp;
	cout<<endl;
}
如果九月份再出这种类型的压轴题就完全可以pass了……

利用Dijkstra算法实现记录每个结点的所有最短路径 我们知道,Dijkstra是解决单源最短路问题的,并且最基本的算法仅能求出最短路的长度,而不能输出路径,本文基于Dinjkstra进行改进,使之能记录源点到任意点的所有最短路径。使用vector<int>来记录一条路径,因为每个结点可能有多条最短路径,因此把这些路径都装在一个vector中,因此可以用一个vector<vector<int> >来表示一个结点的所有最短路径,把所有结点的最短路径都存放起来,又需要一个vector容器,因此所有结点的所有最短路径的集合可以用vector<vector<vecto 阅读详情

相关推荐

最短路径问题—Dijkstra算法及相关例题

最近在做算法题的时候总是遇到Dijkstra相关的题目,之前虽然学过图论的一些算法,但第一次做这类题时完全不知从何入手。看了一些博客,并且在PAT上折腾了几题后,发现一些常用的模板与套路,因此在这里进行一个总结。关于Dijkstra的理论知识可以参考这篇博客:最短路径问题-Dijkstra算法详解 Dijkstra算法 Dijkstra算法往往和dfs结合在一起考,因此这里给出一个求解基础Dijk...

水木今山的博客 2万+

保持图上位置/距离/度来提升GNN表示能力

GNN的经典操作是聚合邻居信息来学习节点表示。在这个过程中,GNN很好的保持了图上的邻居结构,如K层GNN保持了图上的K阶邻居信息。另一方面,图上一些性质(节点之间的距离和位置,节点的度等...

weixin_45519842的博客 839

PAT甲级 1003 Emergency Dijkstra应用

Dijkstra应用

polarours的博客 856

PAT甲级Dijkstra总结

目前PAT甲级中涉及Dijkstra的题目有如下几题:                                           1003 Emergency (25)                                 1018 Public Bike Management (30)                                         ...

qq_37370420的博客 613

香橙派5上跑DeepSeek-R1的避坑指南:从模型下载到NPU加速全流程解析

本文详细解析了在香橙派5(RK3588)上部署DeepSeek-R1蒸馏模型的完整流程与优化技巧。内容涵盖从系统配置、RKLLM工具链编译、模型转换到NPU加速调优的全过程,重点分享了如何利用RK3588的NPU算力实现高效推理,并提供了常见问题的解决方案,为边缘设备部署LLM提供了实用指南。

CAT789的专栏 717

硬件设计--DC/DC电源芯片详解

本文参考:http://www.elecfans.com/article/83/116/2018/20180207631874.html https://blog.youkuaiyun.com/wangdapao12138/article/details/79763343 第一次写博客,不喜勿喷,谢谢!!! DC/DC电源指直流转换为直流的电源,从这个定义上看,LDO(低压差线性稳压器)芯片也应该属于D...

weixin_30794499的博客 7875

第八周.直播.Transformer in Graph

文章目录注意力基础知识论文带读摘要 本文内容整理自深度之眼《GNN核心能力培养计划》 公式输入请参考:在线Latex公式 注意力基础知识 这块是Transformer的基础,之前有写过很多,最主要就是《attention is all you need》,还有两篇之前写过的文章: Seq2Seq几个要点 Transformer 这里就不重复了,列几个之前的问题,如果能答上来,那么说明你对Transformer结构了解非常好: a. 自注意力与注意力的区别? b. 为什么要进行残差连接? c. 为什么要设置多

老毛的博客 629

爬取信用中国里面的行政处罚

result字段名为行政处罚文书号、处罚决定日期、处罚内容、处罚金额、违法事实、处罚机关、公司名称,行政处罚次数。file_path=r'E:\Data analyze\python\行政处罚爬虫/'#路径需要按实际修改。writer = pd.ExcelWriter('统计.xlsx')# 写入Excel文件。src_workbook=file_path+r'行政处罚(名单).xls' #表格名称也要更改。# keyword = input("输入爬取的公司全称必须是全称")

qq_42863025的博客 1674

【PAT】Dijkstra

Dijkstra汇总概述标准套路变化 概述 Dijkstra算法主要用于解决单源最短路径问题。在题目中,一般除了求最短路径还会附加其他条件加以筛选,求得唯一路径。 标准套路 st=起点,en=终点,D[ ]=到各点的最短路径,dis[ ][ ]=各点之间的路径长度(注意,a到b和b到a都要存储),visit[ ]=访问控制,pre[ ]=各点的前驱结点 首先要将不能用0初始化的各对象用fill函数...

Nigel_Zhou的博客 443

常见机械臂模型不用找!Mujoco这儿都有!

高质量的模型集合,franka panda,so-arm100,ur之类的机械臂都有。常见机械臂模型不用找!Mujoco这儿都有!大概346M,网速不行的可以下载zip。

darcsdn 992

OpenStack 之 Epoxy版本 部署实战

OpenStack Epoxy 是 OpenStack 的第 31 个版本,其版本号为 2025.1,于 2025 年 4 月 2 日正式发布。

求知若渴,虚心若愚。 236

【PAT】最短路径算法Dijkstra模板总结

【代码】最短路径算法Dijkstra模板总结。

weixin_50952205的博客 681

外设测试 - ATAES132A 加解密芯片测试

原理 使用芯片官方提供的读写操作库,进行先写后读并校验,确认数据一致。 示例代码 int main(void) { uint8_t ret; aes132p_enable_interface(); ret = write_memory_test(); if (ret != AES132_FUNCTION_RETCODE_SUCCESS) { aes132p_disable_interface(); printf

一个软件工程师的技术笔记 858

最短路径求解(Dijkstra算法)

1. 问题描述(问题来自于PAT A 1003Emergency) As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of ...

二哈 2863

CATIA二次开发一一一计算 CATIA 零件模型在全局坐标系下的包围盒方法

本文介绍了一种在CATIA中计算零件模型全局坐标系下包围盒(BoundingBox)的方法。通过遍历零件几何体特征点,并应用坐标变换矩阵,最终返回精确的零件包围盒。核心步骤包括初始化与输入校验、坐标变换处理、几何体特征点遍历以及全局坐标变换。关键方法涉及CATMathBox操作和坐标变换接口。该方法适用于碰撞检测、可视化优化和装配分析等场景,能够快速判断零件间的空间干涉,提升渲染性能,并计算零件在装配体中的全局位置范围。

工业软件开发 894

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

带路径输出的Dijkstra

注意:在图论问题中,当节点个数多于1000个时用邻接表或者前向星,其中,前向星最快。当节点个数小于1000个时,用邻接矩阵,好写。PAT中点的个数一般不多,在竞赛中有几万个顶点时,必须用前向星。 题目:PAT 1030 https://pintia.cn/problem-sets/994805342720868352/problems/994805464397627392 题意:在无向图中,输出最...

qq_38993096的博客 882

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

最短路径 dijkstra算法实现问题总结

dijkstra算法解决的是单源的最短路径问题 一般输出给定起点到其余各点的最短距离 最短的路径用pre记录前驱 用递归的方法求最短路径 在权值非负时有效 首先 给出dijkstra算法的伪代码 初始化起点 d[s]=0 ,其余为inf for( int i=0;i<N;i++) //有n个结点n循环n次 每次加入一个结点 { int u=-1,min=inf; for(i...

haocoming的博客 1299

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

PAT1003,最短路径,dijkstra代码详解(逐行注解)

PAT1003,最短路径,dijkstra代码详解(逐行注解) dijkstra dijkstra详解: 链接: Dijkstra算法详细讲解——逆风行砾. 1.解决问题:单源最短路径问题 2.主要情况:①双向边与单项边(通过双向赋值实现);②需要输出最短路径(通过前驱节点实现);③每条边有边权(支出),需要输出最小花费;④每个节点有点权(收获),需要输出最大收益;⑤需要输出最小路径条数 3.具体示例代码详解 (本示例中仅对点权与最小路径条数进行了输出,若需要输出最小花费,自行添加每条边的支出情况并保存到c

Beasts136的博客 414

PAT 1030 Travel Plan [dijkstra+DFS] [最短路径输出]

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...

咸鱼夏の翻身观察记录 278

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

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

二哈 6197

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

PAT甲级1003 Dijkstra拓展最短路径的数量+最大权值的最短路径

题目链接:传送门 万万没想到啊!第三题就把我难住了,果然是PAT教我做人,大概了解甲级的难度了,好好刷题吧我个呆瓜 是我太笨了,想不到这么巧妙的方法,说出来呢其实就是迪杰斯特拉单源最短路径算法的一点扩展和变种,可能没见过所以就不会做!!!!!! 哦对,这题不是我自己做的,是看了大佬的博客,以下是链接,自取自取:传送门 但其实大佬没有过多的解释,建议看不懂代码的可以看看我的解释!!!(卑微 这里是...

WAR 600

PAT最短路径问题简单总结

在PAT甲级真题目录中,涉及到最短路经问题求解的有1003、1018、1030、1087、1111。 一般来说,可以用最短路径算法(dijkstra、SPFA等)加上DFS进行求解。 我一般用这些数据结构: struct node{ int v;//与该地点相连的地点的序号 int cost;//两个地点之间的距离 //...由题意确定需要增加变量 node...

Nin7a的博客 526

PAT甲级 1030 旅行计划 dijkstra算法求最短路并输出最短路径

原题链接 给定一张地图,包含 N 个城市,M 条高速公路。 城市之间都能相互连通。 每条高速公路的长度和走该条公路的花费都是已知的,高速公路都是双向的。 现在要从地图中的某个城市前往另一个城市。 请你确定最短路径,当最短路径不唯一时,请你选取花费最小的路径(保证唯一)。 输入格式 第一行包含四个整数 N,M,S,D,分别表示城市数量,公路数量,起点城市编号,终点城市编号。 城市编号从 0 到 N−1。 接下来 M 行,每行包含四个整数 a,b,c,d,表示城市 a 和城市 b 之间存在一条

赵小轩的博客 1872

PAT、蓝桥杯 最短路径总结

文章目录PAT浙江大学-数据结构-2019夏 **07-图6** **旅游规划** (25分) [Dijikstra算法]浙江大学-数据结构-2019夏 08-图7 公路村村通 (30分) [Prim算法]A**1003** **Emergency** **(25分)**A1018 Public Bike Management (30分)A1030 Travel Plan (30分)A1087 All Roads Lead to Rome (30分) [Dijkstra算法 + DFS,最短路径]A1111

刷子的博客 836
上一篇: 【PAT】卡时专题
下一篇: 【PAT】有细节坑点的题+输出技巧题
ccyy-
博客等级 码龄12年 31粉丝 244原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值