首页 > 其他分享 >交个崔鹏题 OJ实践1-B

交个崔鹏题 OJ实践1-B

时间:2023-12-21 18:46:08浏览次数:28  
标签:崔鹏题 交个 OJ v1 int Graph ++ marixWeight graph

#include<iostream> 
#include<malloc.h>
#include<string.h>
using namespace std;
#define MAX 10
#define INF 0;
typedef int E;
typedef struct GraphMartix{
	int vex,edge;
	int marixWeight[MAX][MAX];
	E data[MAX];
}*Graph;
Graph Create(int v){
	Graph g= (Graph)malloc(sizeof(GraphMartix));
	g->edge=g->vex=0;
	memset(g->marixWeight,0,sizeof(g->marixWeight));
	return g;
}
void addVex(Graph g,E v){
	g->data[g->vex++]=v;
	
}
int getIndexByElem(Graph g,E v){
	int i =0;
	while(g){
	if(g->data[i]==v)
		return i;
	i++;
	}
	return -1;
}
void addEdge(Graph g,E v1,E v2,int w){
	int a=getIndexByElem(g,v1);
	int b=getIndexByElem(g,v2);
	g->marixWeight[v1-1][v2-1]=w;
	g->marixWeight[v2-1][v1-1]=w;
	g->edge++;
}
void printMarix(Graph g){
	
	for(int i =0;i<g->vex;i++)
		if(g->marixWeight[0][i]!=0) 
			{
				cout<<g->marixWeight[0][i];
				if(i<g->vex-1) cout<<" ";
			}
	cout<<endl;
}
void Fluid(Graph g){
	for(int i =0 ;i <g->vex;i++)
		for(int j=0;j<g->vex;j++)
			for(int k=0;k<g->vex;k++)
				{
					if(g->marixWeight[j][i]!=0&&g->marixWeight[i][k]!=0&&j!=k)
					{
					
						int newDistance=g->marixWeight[j][i]+g->marixWeight[i][k];
						if (newDistance < g->marixWeight[j][k] || g->marixWeight[j][k] == 0)
                            g->marixWeight[j][k] = newDistance;
					}
				}
				
		
	printMarix(g);
}
int main(){
	Graph graph = Create(4);
	int n;
	cin>>n;
	for (int c =1;c<=n;++c)
		addVex(graph,c);
	int a,b,w;
	while(cin>>a>>b>>w){
		addEdge(graph,a,b,w);	
	}

	//printMarix(graph);
	Fluid(graph);
	
}

标签:崔鹏题,交个,OJ,v1,int,Graph,++,marixWeight,graph
From: https://www.cnblogs.com/Happy-Eric-1/p/17919847.html

相关文章

  • 交个崔鹏题 OJ实践1-A
    #include<iostream>#include<malloc.h>usingnamespacestd;typedefintE;typedefstructNode{ Eelement; structNode*next;}*node;voidinitList(nodend){nd->next=NULL;}voiddeleteDup(nodend){if(nd==NULL)return;......
  • HydroOJ 从入门到入土(9)源码简易修改记录——卍解!
    随着OJ的使用越来越深入,本强迫症总会觉得一些细节有时候不那么符合自己的习惯,但是想改又无处下手,最终还是走上了修改源码的邪路.目录0.重要1.超级管理员查看自测代码2.超级管理员隐身查看比赛/作业题目3.超级管理员隐身查看比赛题目列表4.关掉客观题的多选题部......
  • [转]CryptoJS-中文文档
    原文地址:CryptoJS-中文文档-掘金原始文档:code.google.com/archive/p/c…介绍CryptoJS是一个JavaScript的加解密的工具包。它支持多种算法:MD5、SHA1、SHA2、SHA3、RIPEMD-160的哈希散列,以及进行AES、DES、Rabbit、RC4、TripleDES加解密。散列算法MD5MD5是一种广泛使......
  • 交个崔鹏题 6-A /c++
    #include<iostream>#defineMAX10#include<malloc.h>#include<string.h>#include<stdlib.h>usingnamespacestd;typedefcharE;typedefstructEdge{ Estart; Eend; intweight;}*Edges;typedefstructGraphMatrix{ intvex,edge......
  • ERROR: Could not build wheels for opencv-python, which is required to install py
    目录系统环境问题描述问题解决问题二参考文章系统环境#macOS系统版本$sw_versProductName:MacOSXProductVersion:10.14.4BuildVersion:18E2035#Python版本$python--versionPython3.9.13问题描述安装opencv-python报错,安装失败#安装opencv-python的命令......
  • Could not build wheels for pillow, which is required to install pyproject.toml-b
     参考来源,致敬大佬。ERROR:CouldnotbuildwheelsforPillow,whichisrequiredtoinstallpyproject.toml-basedprojects-CSDN博客报错:Couldnotbuildwheelsforpillow,whichisrequiredtoinstallpyproject.toml-basedprojects的解决-CSDN博客 本人小白......
  • leaflet在vue2中标点 加载geoJSON
    lealfet版本1.9.4vue版本2.6引入:importLfrom'leaflet'  import'leaflet/dist/leaflet.css'  //记得引入样式不然加载瓦片图后地图会错乱1.初始化this.map=L.map(this.mapId,mapInitOptionNew)//this.mapId是容器的idletcenter=[32.666,129.547]const......
  • syoj.1827. 线段传送带题解
    前情提要-三分1827.线段传送带P2571[SCOI2010]传送带省流:三分套三分。在二维平面上有两个传送带,一个从A点到B点,一个从C点到D点,速度分别是p和q,在平面内其他点的速度为r。求A点到D点的最小速度。考虑从A到D的路程一定是\(AE+EF+FD\),即通过这两个点连......
  • [UOJ683] 月球车站
    伏特找到了skip蚤,希望他负责建造月球车站。然而众所周知,skip蚤是一只大鸽子。于是他掏出了口袋里的硬币,在桌面上摆成了一排,要伏特和他玩一局游戏,结束后就开始干活。初始时每枚硬币要么正面朝上,要么背面朝上。游戏会一轮轮进行,如果某一时刻(包括初始时刻)所有硬币都是正面,则游戏......
  • [UOJ682] 月球铁轨
    4s512MB伏特再次找到了工程师,请他们设计铁轨。工程师很快给出了一张模板图纸作为候选方案。图纸上$n$段铁轨排成一行,依次编号为$1,\dots,n$。根据工程师们的设计,第$i$段铁轨的尾部只能和第$i+1$段铁轨的头部相连$(1\leqi<n)$,否则铁轨会变的极为不稳定。伏特不必......