POJ 1502 - MPI Maelstrom(单源最短路)

poj经典数据结构题目解题报告 poj经典数据结构题目解题报告,包括经典的数据结构题目10多道,可以作为学习数据结构系统的资料,包括题目:<br>Pku acm 3253 Fence Repair<br>Pku acm 1861 NetWork<br>Pku acm 2485 Highways<br>Pku acm 1258 Agri-Net<br>Pku acm 3278 Catch That Cow<br>Pku acm 2253 Frogger<br>Pku acm 1062 昂贵的聘礼<br>Pku acm 1125 Stockbroker Grapevine<br>Pku acm 1611 The Suspects<br>Pku acm 2492 A Bug's Life<br>更多请访问:http://blog.youkuaiyun.com/china8848<br> 立即下载

MPI Maelstrom
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 4531 Accepted: 2744

Description

BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swigert, has asked her to benchmark the new system. 
``Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,'' Valentine told Swigert. ``Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.'' 

``How is Apollo's port of the Message Passing Interface (MPI) working out?'' Swigert asked. 

``Not so well,'' Valentine replied. ``To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.'' 

``Is there anything you can do to fix that?'' 

``Yes,'' smiled Valentine. ``There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.'' 

``Ah, so you can do the broadcast as a binary tree!'' 

``Not really a binary tree -- there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don't necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.''

Input

The input will describe the topology of a network connecting n processors. The first line of the input will be n, the number of processors, such that 1 <= n <= 100. 

The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j. 

Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied. 

The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.

Output

Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.

Sample Input

5
50
30 5
100 20 50
10 x x 10

Sample Output

35


=========================

一个无向图,输入的是一个不含对角线的下三角,三角阵里面每个值表示两点之间连接的时间,求1能连接到全部点的最小时间

也就是求1到各点的最短路,找出最大值

单源最短路应该用dijkstra的吧,数据很小只有100简单的用floyd也过了


dijkstra:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>

const int INF=0x3f3f3f;
int n;
int map[111][111],dis[111],vis[111];
char str[5];

void dijkstra(int s)
{
    memset(vis,0,sizeof(vis));
    memset(dis,INF,sizeof(dis));
    dis[s]=0;
    for(int rp=1;rp<=n;rp++)
    {
        int u=0,temp=INF;
        for(int i=1;i<=n;i++)
        {
            if(!vis[i]&&dis[i]<temp)
            {
                temp=dis[i];
                u=i;
            }
        }
        if(u==0) return;
        vis[u]=true;
        for(int i=1;i<=n;i++)
        {
            if(map[u][i]<INF&&dis[i]>dis[u]+map[u][i])
                dis[i]=dis[u]+map[u][i];
        }
    }
}

int main()
{
    scanf("%d",&n);
    memset(map,INF,sizeof(map));
    for(int i=1;i<=n;i++) map[i][i]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            scanf("%s",str);
            if(str[0]!='x') map[i][j]=map[j][i]=atoi(str);
        }
    }
    dijkstra(1);
    int ans=-1;
    for(int i=2;i<=n;i++)
    {
        if(dis[i]>ans) ans=dis[i];
    }
    printf("%d\n",ans);
    return 0;
}


floyd:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

const int INF=0x3f3f3f;
int n;
int dis[111][111];
char str[5];

void floyd()
{
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}

int main()
{
    scanf("%d",&n);
    memset(dis,INF,sizeof(dis));
    for(int i=1;i<=n;i++) dis[i][i]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<i;j++)
        {
            scanf("%s",str);
            if(str[0]!='x') dis[i][j]=dis[j][i]=atoi(str);
        }
    }
    floyd();
    int ans=-1;
    for(int i=2;i<=n;i++)
    {
        if(dis[1][i]>ans) ans=dis[1][i];
    }
    printf("%d\n",ans);
    return 0;
}


COMSOL电磁仿真-网格剖分-边界层 介绍COMSOL在低频电磁场中边界层网格的剖分方法。 阅读详情

相关推荐

保姆级教程:在Ubuntu 20.04上搞定PX4飞控与T265的视觉定位(附避坑指南)

本文提供在Ubuntu 20.04上配置PX4飞控与T265视觉定位系统的详细教程,涵盖驱动安装、ROS与MAVROS桥接、PX4参数调优及故障排查。通过实测验证的步骤和避坑指南,帮助开发者实现厘米级精度的视觉定位,特别适合室内无人机应用。

weixin_29038155的博客 248

POJ 1502 dijkstra()

dijkstra()算法的裸题。。。。。。。。。题目: MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2858   Accepted: 1681 Description BIT has recently taken d

1467

Isaacgym使用操作指南

Isaac Gym 是一个强大的仿真工具,特别适合那些需要进行大规模并行仿真和训练的机器人和强化学习任务。通过 GPU 加速、深度学习集成和丰富的物理仿真能力,Isaac Gym 能够显著提高仿真和训练效率,是机器人学和 AI 研究中的一大利器。

Tony Wey的博客 1万+

poj 1502 Dijkstra 求最短路径。

现在这边感谢喵呜晚上给我讲了Dijkstra 算法思想和编程方法。  昨晚两点睡觉 今天还是那么早就醒,嗯嗯 这样的日子让我觉得很充实。。        这道题是简单题,赤裸裸的Dijkstra算法题。  题意就是求第一个点到各个点最短路径中的最大值。MPI MaelstromT

ACM梦。。。。 1759

从PCEP到PCAP:一个数据分析师的Python认证升级之路与学习规划

本文详细介绍了数据分析师从PCEP(初级)到PCAP(中级)的Python认证升级路径,包括考试内容、备考策略和时间规划。通过系统化的学习,读者可以掌握Python在数据分析中的核心应用,提升职业竞争力。文章还提供了实用的代码示例和认证考试对比,帮助读者高效备考。

weixin_27427619的博客 440

常学常新:《Attention Is All You Need》万字解读!

常学常新:《Attention Is All You Need》万字解读!

hunteritself的博客 3649

最小堆实现优先队列+Dijkstra 解决最短路问题

某著名游戏公司上机题目 题目回来网上搜了一把是这样的 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Va...

breakpoints_的博客 1751

IPMI的SOL (Serial Over LAN) 和 UART

UART全名是Universal Asynchronous Receiver/Transmitter(通用異步接收/发送器),它是一个常用的異步串行传输协议。透过UART传输前,接收方须要先知道传输方的鲍率(Baud rate):单位时间内,讯号状态变化的次数。例如 115200 bps,表示每秒会传送115200个bits--> 因此读取率就是 1/115200=8.6微秒读取一次讯号。封包内的资料长度:通常是 8bits。

yeiris的博客 1万+

POJ - 150 MPI Maelstrom(最短路dijkstra)

https://vjudge.net/problem/POJ-1502 POJ - 150 MPI Maelstrom(最短路dijstra)题目分析AC代码 题目 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Vale

斯文~ 298

速腾聚创激光雷达复现FAST-LIO

记录复现FAST-LIO算法的过程和,代码梳理和理解。FAST-LIO的简化版、注释版。速腾激光雷达

abanchao的博客 2930

AI量化学习入门指南:从零开始掌握人工智能投资策略

量化投资:利用数学模型和计算机算法进行投资决策的方法算法交易:自动执行预定义交易规则的系统机器学习:让计算机从数据中学习并改进的技术回测:用历史数据检验交易策略表现的过程特征工程:将原始数据转化为模型可理解的输入过拟合:模型过度适应历史数据,导致未来表现不佳夏普比率:衡量单位风险所获得的超额收益AI量化投资不仅仅是技术的应用,更是一种理性、系统化的投资哲学。它不追求预测市场的每一个拐点,而是通过概率思维和风险管理,在不确定性的市场中寻找统计优势。

AGI×大数据,开启智能时代的认知跃迁;解码AGI,赋能数据驱动的智能革命。 1130

[kuangbin]专题四 最短路练习 MPI Maelstrom POJ - 1502【dijkstra】

【题目描述】 While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at a time...

inv0ker的博客 253

OpenClaw插件配置错误修复完全指南

插件文件名是插件目录结构正确package.json配置正确OpenClaw的插件系统还在快速迭代,偶尔会遇到这种配置问题。看错误信息检查配置文件检查实际文件对比差异修复问题大部分问题都能解决。查看官方文档:https://openclaw.ai/docs提Issue:https://github.com/openclaw/openclaw/issues加入Discord社区求助快速修复命令汇总。

Maynor的博客 4096

POJ 1502 - MPI Maelstrom(单源最短路)

MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8783 Accepted: 5403 DescriptionBIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Ody

Snakeflute的博客 381

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

poj1502 MPI Maelstrom(单源最短路)

题意:表面乍一看output是输出最小值,但仔细研究可以发现,这个最小值是从点1到所有点所花时间的最小值,其实是访问这些节点中的最大值,因为只有访问了最长时间的那个点才算访问了所有点。所以求最短路之后求最大值。 #include <iostream> #include <cstring> #include <cstdio> using namespa...

weixin_30294021的博客 113

老版QQ原生表情gif动态

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

poj 1502 MPI Maelstrom(单源最短路dijkstra)

题目真是长得头疼,好多生词,给跪。 大概题意就是给你

渐近自由 1035

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 1502 MPI Maelstrom(单源最短路)

题目链接:kuangbin带你飞 专题四 最短路练习 G - MPI Maelstrom题意 n个处理器,第一个处理器要广播消息到其他所有的处理器,求需要时间最短是多少(从第一个点出发,求到其他点最短路的最大值) 思路 没什么可说的,单源最短路,dijkstra。 代码#include<iostream> #include<cstring> #include<cmath> #include<

YiShi's Blog 1326

POJ 1502 MPI Maelstrom(单源最短路|Dijkstra实现)

//单源最短路。最后答案应该处从起点到其他结点最短路中的最大值。 #include #include using namespace std; const int INF = 50000000; int G[105][105]; bool flag[105]; int dis[105]; int n; int dijkstra(int st) { int res = INF*(-1); for(int i = 0;i

Czy 1200

POJ 1502 MPI Maelstrom(单源最短路|Floyd实现)

//单源最短路Floyd实现。最后答案应该处从起点到其他结点最短路中的最大值。 #include #include using namespace std; const int INF = 50000000; int G[105][105]; bool flag[105]; int dis[105]; int n; int Floyd() { for(int k = 0;k

Czy 1172

poj1502 MPI Maelstrom,单源最短路的最长距离,dijkstra + 优先队列

点击打开链接 求顶点1到其他点的最短距离的最长距离。。 测试。。dijkstra + 优先队列 #include #include #include #include #include #include #include #include #include #include #include #define for0(a,b) for

天亮说晚安 2054

POJ 1502 MPI Maelstrom 【单源最短路中求最大值】

Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKe

Kelisiya 374

【POJ 1502 --- MPI Maelstrom】单源最长路径,Floyd

【POJ 1502 --- MPI Maelstrom】单源最长路径,Floyd 题目来源:点击进入【POJ 1502 — MPI Maelstrom】 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared me...

来日浅谈的博客 617

POJ 1502 MPI Maelstrom(最短路)

【题目链接】 http://poj.org/problem?id=1502 题目意思 多个主机要通信,由于各种乱七八糟的原因任意两台主机的通信时间不一样,现在给你任意两台之间的通信时间(通信是双向的所以给的是矩阵的下三角)。通信同时进行问从一号主机开始最晚收到通信的主机时间。 解题思路 单源最短路,输入时处理下就可以了,其他都是模板。 代码部分 #include &...

绝丶爵的博客 206

POJ-1502 MPI Maelstrom(最短路)

POJ-1502 给出下三角矩阵 求单源最短路中的最长路 求下最短路就好,考读题。。//求单源最短路中的最长路 #include <cstdio> #include <algorithm> #include <queue> #include <cstring> #include <cmath> #include <cstdlib> using namespace std; typedef pai

lanvent的博客 390

poj1502 MPI Maelstrom 裸的最短路

好久没写了,发现还是写写,一是

396

POJ1502 MPI Maelstrom Dijkstra

题意给出图,从点1出发,求到最后一个点的时间。思路单源最短路,没什么好说的。注意读入的时候的技巧。代码#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int INF = 1000000000; const int maxn = 110; i

Bill_Utada的成长之路 886
上一篇: HDU 2647 - Reward(拓扑排序)
下一篇: SGU 180 - Inversions(逆序数)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值