首页 > 其他分享 >竞赛摩托

竞赛摩托

时间:2023-04-25 11:44:06浏览次数:30  
标签:摩托 竞赛 int void vertexnum Print Floyd MaxVertexNum

#include <iostream>
using namespace std;
const int N=2500;
    int p[N];
const int MAXW = 30000;
const int MaxVertexNum = 30;
typedef char VertexType;
int ans=0;
class MGraph
{
public:
    void CreateGraph();
    void ShortestPath_Floyd();
    void Print_Path_Floyd(int v,int w);

private:
    int vertexnum;
    VertexType vertexs[MaxVertexNum];
    int edgenum;
    bool P[MaxVertexNum][MaxVertexNum][MaxVertexNum];
    int D[MaxVertexNum][MaxVertexNum];
    int arcs[MaxVertexNum][MaxVertexNum];
};

void MGraph::CreateGraph()
{
    cin >> vertexnum >> edgenum;
    int x,d;
    cin>>x>>d;
    for(int i=1;i<x;i++){
    cin>>p[i];
    }
    for (int i = 0; i < vertexnum; i++)
        for (int j = 0; j < vertexnum; j++)
            arcs[i][j] = MAXW;

    for (int i = 0; i < edgenum; i++)
    {
        int v1, v2, w;
        cin >> v1 >> v2 >> w;
        arcs[v1][v2] = w;
    }
}

void MGraph::ShortestPath_Floyd()
{//用Floyd算法求有向图G中各对顶点v和w之间的最短路径P[v][w]及其带权长度D[v][w]

    //若P[v][w][u] = 1,则u是从v到w当前求得的最短路径上的顶点

    for (int v = 0;v<vertexnum;v++)
        for (int w = 0; w < vertexnum; w++)
        {
            D[v][w] = arcs[v][w];
                for (int u = 0; u < vertexnum; u++) P[v][w][u] = 0;
            if (D[v][w] < MAXW)//从v到w有直接路径
            {
                P[v][w][v] = 1;
                P[v][w][w] = 1;
            }
        }
    for (int u = 0;u< vertexnum;u++)
            for (int v = 0;v<vertexnum;v++)
                for (int w = 0; w < vertexnum; w++)
                {
                    if (D[v][u] + D[u][w] < D[v][w])
                    {
                        D[v][w] = D[v][u] + D[u][w];
                        P[v][w][u] = 1;
                    }
                }
}

void MGraph::Print_Path_Floyd(int v, int w)
{

    int i;
    for (i = 0; i < vertexnum; i++)
    if (i != v && i != w && P[v][w][i] == true) break;

    if (i >= vertexnum) {
        ans=ans+arcs[v][w];
        }
        else
        {
            Print_Path_Floyd(v, i);
            Print_Path_Floyd(i, w);
        }
    
}


int main()
{
    MGraph g;
    g.CreateGraph();
    g.ShortestPath_Floyd();
    int v,w;
    g.Print_Path_Floyd(v, w);
    cout<<ans;

}

 

标签:摩托,竞赛,int,void,vertexnum,Print,Floyd,MaxVertexNum
From: https://www.cnblogs.com/lhf123/p/17352158.html

相关文章

  • 第九届福建省大学生程序设计竞赛-重现赛(感谢承办泉州师范学院)
    Inthedistantspace,thereisatechnologicallyadvancedplanet.OnedaytheyprovidedtheEarthwithacodethatcouldachievetheultimatemeaningoftheuniverse.Peoplewereveryhappy,butfoundthatthiscodecanonlyrunoncomputerswithawordle......
  • 第九届福建省大学生程序设计竞赛-重现赛(感谢承办泉州师范学院) spfa变形
    Xzzisachildwithsevereprocrastinations.Thenewsemesterbegins,Hestillhasalotofhomeworktodo.Now,heneedsyourhelp.Asthebestfriend,youaregoodatmath.So,youwillhelphimdosomemathhomework.NowXzzwantstogotoyourhome.Y......
  • 摩托车验车
    摩托车验车,无需实车线下验车,对于改装较多,或者类似黄龙600等线下验车排气过不去等均可,快来联系我吧现在新法规为第6年线下年检,所以需要线下年检的小伙伴快来联系我啦~......
  • 青岛市程序设计竞赛冲刺①
    2021年青岛市小学组第三题原题: 解题代码:#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>usingnamespacestd;constintN=5e2+5,dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};intn,m,vis[N][N],ans=0;charc......
  • 华中农业大学2023年十二届程序设计竞赛(补题)
    题目地址B.写信题意:有n个信封和n封信,问全部装错有多少种可能Solution全错排问题,对于i=k的情况,我们可以从i=k-1和i=k-2转移过来一种是k-1个全错排,然后从前面k-1个选出一个信封与第k个交换另一种是任选一个j,有1<=j<=k-1放在k,这样除了k和j以外还有k-2个数进行全错位排列,这样我......
  • 2022年中国大学生程序设计竞赛女生专场-比赛题解
    比赛链接:Dashboard-2022年中国大学生程序设计竞赛女生专场-CodeforcesA.减肥计划(模拟)模拟,如果队列第一个人体重是最大的了,则这个人的位置不会再变,直接输出即可。#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_......
  • 《算法竞赛进阶指南》 第五章 237. 程序自动分析
    地址https://www.acwing.com/problem/content/239/在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足。考虑一个约束满足问题的简化版本:假设x1,x2,x3,…代表程序中出现的变量,给定n个形如xi=xj或xi≠xj的变量相等/不等的约束条件,请判定是否可以分......
  • 【ACM算法竞赛日常训练】DAY16【奇♂妙拆分】【区区区间间间】【小AA的数列】数学 |
    DAY16共3题:奇♂妙拆分(简单数学)区区区间间间(单调栈)小AA的数列(位运算dp)......
  • papamelon 302. 碰撞游戏 Stripies(挑战程序设计竞赛)
    地址https://www.papamelon.com/problem/302http://poj.org/problem?id=1862解答自取了几个样例从大到小和从小到大进行模拟发现最大的数最先碰撞则开方的次数最多,所以需要结果最小,则优先去最大的数进行合并。代码如下#include<iostream>#include<algorithm>#includ......
  • 挑战程序设计竞赛---Ants
    Anarmyofantswalkonahorizontalpoleoflengthlcm,eachwithaconstantspeedof1cm/s.Whenawalkingantreachesanendofthepole,itimmediatellyfallsoffit.Whentwoantsmeettheyturnbackandstartwalkinginoppositedirections.Wekno......