G - MPI Maelstrom(Dijkstra)

G - MPI Maelstrom G - MPI Maelstrom 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 b 阅读详情
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

求取最短路径的最大值,输入为下三角……

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF 0x3f3f3f3f
using namespace std;
int ma[12111][12111];
int v[1212121];
int dis[12121211];
void Dijkstra(int n)
{
   int ans = 0;
   for(int i=1;i<=n;i++)
   {
      v[i] = 0;
      dis[i] = ma[1][i];
   }
   dis[1] = 0;
   for(int j =1;j<=n;j++)
   {
      int k = -1;
      int minx = INF;
      for(int i=1;i<=n;i++)
      {
         if(!v[i]&&dis[i]<minx)
         {
           minx = dis[i];
           k = i;
         }
      }
      if(k==-1)
      {
        cout<<ans<<endl;
        return;
      }
      ans = max(minx, ans);//最短路径的最大值
      v[k] = 1;
      for(int i=1;i<=n;i++)
      {
         if(!v[i]&&dis[k]+ma[k][i]<dis[i])
         {
            dis[i] = dis[k] + ma[k][i];
         }
      }
   }
   cout<<ans<<endl;
}
int main()
{
   int n;
   scanf("%d", &n);
   char c[1212];
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<i;j++)
       {
          scanf("%s", c);//用字符串输入
          if(c[0]=='x')//处理x,赋值INF
          {
             ma[i][j] = ma[j][i] = INF;
          }
          else
          {
             int ans = 0;
             int len = strlen(c);
             for(int k=0;k<len;k++)
             {
                 ans = ans * 10 + (c[k] - '0');//转换为数字
             }
             ma[i][j] = ma[j][i] = ans;
          }
       }
       for(int j=i;j<=n;j++)
       {
          if(i==j)
          ma[i][i] = 0;
          if(ma[i][j]==-1)
          ma[i][j] = INF;
       }
   }
   Dijkstra(n);
   return 0;
}
Perplexity SPACE沙箱平台:安全AI开发环境实战解析 沙箱技术通过资源隔离和权限控制创建受限执行环境,其核心原理是容器化隔离机制。在AI开发领域,这种技术解决了环境配置复杂性和安全风险等关键问题。SPACE沙箱平台作为AI代码执行环境,提供了标准化的开发沙箱,支持Python生态和主流AI框架。通过实战案例展示,该平台特别适用于情感分析等NLP任务的快速原型验证,帮助开发者在安全隔离的环境中测试AI模型和算法,显著提升开发效率并降低系统风险。 阅读详情

相关推荐

WinForm轻松打造AntDesign现代化工具栏

摘要: 本文介绍如何在WinForm中利用AntdUI库实现AntDesign风格工具栏,包括安装配置、动态生成按钮/下拉菜单、布局优化及主题美化。通过AntButton、AntDropdown等控件结合事件绑定,可快速构建支持图标、工具提示、权限控制的现代化工具栏,并解决常见图标加载、布局错乱问题。最后提供代码示例与响应式设计技巧,助你打造高效美观的WinForm界面。 (字数:150)

java专栏 1593

【代码超详解】POJ 1502 MPI Maelstrom(Dijkstra 模板题)

一、题目描述 二、算法分析说明与代码编写指导 三、AC 代码 #include<cstdio> #include<algorithm> #include<bitset> #include<cctype> #pragma warning(disable:4996) using namespace std; unsigned A[101][101],...

COFACTOR 346

深入解析Sigma Delta调制器 —— 从电流采样到数字信号处理的完整链路

本文深入解析了Sigma Delta调制器的工作原理与应用。通过剖析过采样、噪声整形与负反馈核心机制,并结合AMC1306等实例,详细阐述了从电流采样到数字信号处理的完整链路。该技术凭借其高精度和高抗干扰能力,在ADC、电流测量及音频处理等领域发挥着关键作用。

ttt77的博客 643

poj 1502 Dijkstra 求最短路径。

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

ACM梦。。。。 1759

土壤水动力学_前 言

Van Genuchten (V-G) 模型是土壤水分特征曲线中最常用的模型之一。它通过数学方程描述了土壤基质吸力与体积含水量之间的关系,被广泛应用于土壤水分运移、土壤盐渍化、边坡稳定性等研究领域。V-G模型是描述土壤水分特征曲线的重要工具,但它并不是完美的。在实际应用中,需要根据土壤类型、试验条件等因素选择合适的模型。土壤基质吸力是土壤水分学中的一个重要概念,它对土壤水分的保持、植物的生长以及土壤的工程性质都有重要影响。

weixin_44259522的博客 5331

【Agent从入门到实践】40 容错优化:异常处理、重试机制、降级策略

各位小伙伴,咱们的多Agent框架一路优化到现在,决策快、执行效率高、资源用得省,看似啥都行,但只要一遇到网络波动、工具故障、数据异常调用web_search工具时网络超时,整个检索任务直接失败,写作Agent没数据可用向量库连接异常,向量检索直接崩掉,依赖检索结果的Agent全趴窝单个Agent执行出错,整个并行任务流程直接中断,前功尽弃高并发下部分工具调用失败,框架没有备用方案,只能返回任务失败说白了,咱们之前的框架只有正常执行逻辑,没有异常兜底逻辑。

人工智能AI技术 910

POJ 1502 dijkstra()

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

1467

UWB芯片DW3000之PDOA测向实现源码

本文详细介绍如何基于UWB芯片DW3000之PDOA测向的源码实现。

DT程序员的博客 2616

最小堆实现优先队列+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

飞牛fnNAS免费内网穿透之zerotier篇

本文介绍了如何通过ZeroTier实现飞牛NAS的远程文件共享。首先,用户需要在ZeroTier官网注册账号并创建虚拟局域网。接着,分别在Windows和飞牛NAS上安装ZeroTier客户端,并通过SSH登录飞牛NAS进行配置。安装完成后,用户可以在ZeroTier页面中授权设备加入虚拟局域网。最后,通过Windows的“网上邻居”功能访问飞牛NAS的共享文件夹,实现跨局域网的文件共享。这种方法不仅适用于文件共享,还可以用于打印机共享和远程桌面连接。

dgnankai的专栏 2466

置顶必读(1) |《滚雪球学SpringBoot 3.x》· 高质量专栏介绍,你值得拥有!

《滚雪球学SpringBoot 3.x》 并不是普通的技术讲解合集,它是专为开发者精心设计的系统化学习路径。通过不断“滚动学习”,我们将带领你从基础入门到高阶应用,从理解每一行代码到设计和优化大规模分布式系统,最终帮助你成长为一位精通 spring架构 的工程师。

**My Coding Family** 12万+

[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

手把手教你学Simulink——基于经典滤波器设计的场景:低通滤波器(LPF)的设计与频率响应仿真

滤波器是信号处理领域中非常重要的组件,用于去除不需要的频率成分或者提取有用的频率信息。低通滤波器(Low-Pass Filter, LPF)允许低于某个特定截止频率的信号通过,同时衰减高于该截止频率的信号。在本教程中,我们将学习如何使用设计一个简单的模拟低通滤波器,并对其频率响应进行仿真分析。本文介绍了如何使用设计一个简单的模拟低通滤波器,并通过仿真展示了其应用效果。通过这样的实践,您不仅能够加深对滤波器工作原理的理解,还能掌握利用Simulink进行滤波器设计与仿真的基本技能。

MHD0815的博客 5720

G - MPI Maelstrom POJ - 1502(dijkstra)

G - MPI Maelstrom POJ - 1502 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. ...

石旭先森的博客 257

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

【G - MPI Maelstrom】

思路: 翻译题…翻译题… 难道是我校被Q了吗? 正权无向稠密图,求源点到所有点的最短路,输出最长一条的长度。 使用:Dijkstra,邻接矩阵,atoi函数。 代码: 0ms 748kB ​//0ms 748kB #include <iostream> #include <cstdio> #include <algorithm> #include &...

Masker 194

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

【图论--Dijkstra】POJ 1502 MPI Maelstrom

  POJ 1502 MPI MaelstromDescription 题目链接-&gt;点击打开链接InputThe 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...

荷叶田田 469

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

POJ 1502 MPI Maelstrom(Dijkstra)

POJ 1502 MPI Maelstrom(Dijkstra) http://poj.org/problem?id=1502 题意: (整个第一段题意描述都是无关的话,可以直接看input)题目的输入给了你一个n个节点的无向图的邻接矩阵的下三角部分.要求你输出从第0个点到所有其他点的距离的最大值. 分析:        Dijkstra入门题,直接用刘汝佳的模板处理即可. AC代码:

code 1214

POJ - 1502 MPI Maelstrom (dijkstra)

题意:给定一个下三角矩阵,询问从1开始到其他点的最短路径中,最长的那个是多少。 输入:N编号个数,然后对应 邻接矩阵的权值 思路:根据题意就是直接使用 dijkstra,因为是单源最短路且没有负权。然后把得到的dist 去循环一次找到最大的值即可 对于图的存储,由于编号数比较小,而且又是矩阵,所以直接开个邻接矩阵写了 完整题解: #include <iostre...

157

MPI Maelstrom poj - 1502 (floyd模板,dijkstra模板)

O(N^3) 因为此题n的范围较小,可以用floyd #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int inf = 0x3f3f3f3f; int n, g[110][110]; char str[20]; void floyd() { ...

ChenXiLian_的博客 225

POJ 1502 MPI Maelstrom——dijkstra

这题是个很简单的dijkstra模板题,但是题目很长,不好理解,这里只说一下题意: 以矩阵下三角的形式给出一张图(无自环, x表示边不存在, 开头的n为矩阵大小),求第一个节点到其他节点的最短路; 额。。。输入的倒数一二行看似是相同的,其实一个是3个一个是4个,,,这个应该能看出来把。。。 #include #include #include #include #include #

hao_zong_yin的博客 532

kuangbin 专题四:G题(dis数组性质) MPI Maelstrom

G - MPI Maelstrom POJ1502 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication ...

aboc43983的博客 205

G - MPI Maelstrom(最短路中的最长路)

题意:有n个点,求从一个点到其他所有点的最短路中的最长路。SPFA和Dijkstra都可以。 SPFA: #include&lt;iostream&gt; #include&lt;cstring&gt; #include&lt;vector&gt; #include&lt;queue&gt; #include&lt;stdio.h&gt; const int maxn=108; const ...

cherish_lin的博客 263

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

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

渐近自由 1035

MPI Maelstrom POJ - 1502

一、内容 实验室有很多台计算机,由于每个人计算机的性能不同,导致计算机之间发送信息的速度不同,所以花费时间不同。 消息从第一台电脑发送到第二台电脑后,这两台电脑能再向其他电脑发送消息,就是一种类似二叉树的结构。 当然并不是真正的二叉树——我们的计算机有一些特殊的特性,我们应该加以利用。 我们的计算机允许同时向连接到它的任意数量的其他计算机发送消息。 然而,消息不一定同时到达目的地——这涉...

Tizzi的博客 710

poj-1502(MPI Maelstrom)

今天做到这道题,题目那么鬼长。。。

blackturtle的博客 622

G - MPI Maelstrom POJ - 1502

G - MPI Maelstrom POJ - 1502 思路: 乍一看,我觉得使求一棵最小生成树,然后找到从根节点到叶节点的最长的一条 转念一想,这不就直接是从起点到各个点的最短路中最长的一条即可,直接转化为 DJ 板子题 #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<algorithm> using namespace std;

一只养生的程序猿。 153
上一篇: F - Wormholes(Bellman_Ford)
下一篇: 2017 ACM/ICPC Asia Regional Shenyang card card card(补题)
mrxs
博客等级 码龄10年 102粉丝 381原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值