graph theory:

本文详细介绍了一种用于解决图中所有顶点对之间的最短路径问题的经典算法——Floyd算法,并通过一个具体的C++实现示例展示了如何应用该算法。文章还提供了一个完整的代码示例,帮助读者更好地理解和掌握算法的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Floyd : City of Blinding Lights

重点距离为0 

平时都不用floy,一到用时,竟然写不来。。。

#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;
const int N = 500;
const int inf = 0x3f3f3f;
int g[N][N];

int main(){
    //cout<<inf<<endl;
   // cout<<400*400*350/2<<endl;
   // cout<<inf+inf<<endl;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            g[i][j] = inf;
            if(i==j)g[i][j] = 0;
        }
    }
    int n,m;
    scanf("%d%d",&n,&m);
    //scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++){
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        u--;
        v--;
        g[u][v] = w;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(g[i][j]>0&&g[i][k]<inf&&g[k][j]<inf&&g[i][j]>g[i][k]+g[k][j]){
                    g[i][j] = g[i][k]+g[k][j];
                    //g[k][i] = g[i][j]+g[j][k];
                }
            }
        }
    }
    int Q;
    scanf("%d",&Q);
    for(int i=0;i<Q;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        u--;
        v--;
        if(g[u][v]!=inf){cout<<g[u][v]<<endl;}
        else cout<<-1<<endl;
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/EdsonLin/p/5713286.html

组合数学与图论,英文版。内置高清图片,缺陷没有书签。 目录如下: 1 Fundamentals 7 1.1 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.2 Combinations and permutations . . . . . . . . . . . . . . . . . 11 1.3 Binomial coefficients . . . . . . . . . . . . . . . . . . . . . . . 16 1.4 Bell numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 1.5 Choice with repetition . . . . . . . . . . . . . . . . . . . . . . 27 1.6 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . 32 1.7 Sperner’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . 36 1.8 Stirling numbers . . . . . . . . . . . . . . . . . . . . . . . . . 39 2 Inclusion-Exclusion 45 2.1 The Inclusion-Exclusion Formula . . . . . . . . . . . . . . . . . 45 2.2 Forbidden Position Permutations . . . . . . . . . . . . . . . . . 48 3 3 Generating Functions 53 3.1 Newton’s Binomial Theorem . . . . . . . . . . . . . . . . . . . 53 3.2 Exponential Generating Functions . . . . . . . . . . . . . . . . 56 3.3 Partitions of Integers . . . . . . . . . . . . . . . . . . . . . . . 59 3.4 Recurrence Relations . . . . . . . . . . . . . . . . . . . . . . . 62 3.5 Catalan Numbers . . . . . . . . . . . . . . . . . . . . . . . . . 66 4 Systems of Distinct Representatives 71 4.1 Existence of SDRs . . . . . . . . . . . . . . . . . . . . . . . . 72 4.2 Partial SDRs . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4.3 Latin Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 4.4 Introduction to Graph Theory . . . . . . . . . . . . . . . . . . 83 4.5 Matchings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 5 Graph Theory 91 5.1 The Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 5.2 Euler Circuits and Walks . . . . . . . . . . . . . . . . . . . . . 96 5.3 Hamilton Cycles and Paths . . . . . . . . . . . . . . . . . . . 100 5.4 Bipartite Graphs . . . . . . . . . . . . . . . . . . . . . . . . 103 5.5 Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 5.6 Optimal Spanning Trees . . . . . . . . . . . . . . . . . . . . 108 5.7 Connectivity . . . . . . . . . . . . . . . . . . . . . . . . . . 110 5.8 Graph Coloring . . . . . . . . . . . . . . . . . . . . . . . . . 117 5.9 The Chromatic Polynomial . . . . . . . . . . . . . . . . . . . 124 5.10 Coloring Planar Graphs . . . . . . . . . . . . . . . . . . . . . 125 5.11 Directed Graphs . . . . . . . . . . . . . . . . . . . . . . . . 129 6 P´olya–Redfield Counting 135 6.1 Groups of Symmetries . . . . . . . . . . . . . . . . . . . . . 137 6.2 Burnside’s Theorem . . . . . . . . . . . . . . . . . . . . . . 140 6.3 P´olya-Redfield Counting . . . . . . . . . . . . . . . . . . . . 146 A Hints 151 Index 153
一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值