poj1502 MPI Maelstrom(dijkstra模板)个人理解

cf 670D2 Magic Powder - 2 二分裸题 D2. Magic Powder - 2 time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard outputWaking up in the morning, Apollinaria decided to bake cookies. To bake o 阅读详情
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">MPI Maelstrom</span>
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 7632 Accepted: 4664
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






题目大意:在一个无负边无向图内,求一个点到其他所有点的最短路径的最大值
思路:dijkstra


dijkstra介绍:
(注:本文中dis[i]表示起点到i点的最短路径,map[i][j]表示从i到j的直接距离)
    dijkstra算法是一种具有最优子结构的算法。假设某一点u到某一点v的最短路径为u->s1->s2...->sn->v,那么u到sn也一定是最短路径,否则可以有另一条路径u->sn-1可以替换之。
根据这一思想,我们可以推出dijkstra的步骤:
   1.  找出离起点最短路径最短的一点u,将u标记为已访问过。

   2.  遍历所有未被访问(即未被包含进最短路里的)的点v,如果dis[v]>dis[u]+map[u][v]则更新dis值

个人理解:dijkstra的算法其实是不停地以确定的最短路径到达的点为媒介,更新以此点为跳板到其他所有点的较短距离(不一定是最短),跟prim的思想有点类似。


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int MAX=0xfffffff;
int map[110][110];
int vis[110];
int dis[110];
char str[100];
int i,j,k,m,n;
void init(int n)
  {for(int i=2;i<=n;i++)
  	 for(int j=1;j<i;j++)
  	 	 {
  	 	 scanf("%s",str);
         if(str[0]=='x'){map[i][j]=-1;map[j][i]=-1;}
           else 
           	  {int m=0;
               for(int k=0;k<strlen(str);k++)
               	 {
               	 	m=m*10+str[k]-'0';
               	 }
                map[i][j]=m;	 //此处是双向图
                map[j][i]=m;
           	  }
         }
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++)dis[i]=MAX;     
  }

void dj(int s)
 {dis[s]=0;
  int now=MAX;
  int t;
  for(int i=1;i<n;i++)
    { now=MAX;
      for(int j=1;j<=n;j++)  //寻找确定的到某一点的最短路径
         if(vis[j]==0 && dis[j]<now)
         {
          now=dis[j];
          t=j;
         }   
      vis[t]=1;   
      for(int j=1;j<=n;j++)  //更新以t点为跳板的所有点的较短路径值
        if(vis[j]==0 && map[t][j]!=-1 && dis[j]>dis[t]+map[t][j])
        {dis[j]=dis[t]+map[t][j];
        }

    }
    
 }

int main(int argc, char const *argv[])
{  
   while(~scanf("%d",&n))
   	  {init(n);
       /*for(i=1;i<=n;i++)
        {printf("\n");
         for(j=1;j<=n;j++)printf("%d ");
        }*/ 
       dj(1);
       sort(dis+1,dis+1+n);
       printf("%d\n",dis[n]);
   	  }  
	return 0;
}



Blazor Session设置 微软官方封装了一些浏览器的操作,其中就有Session的操作的封装ProtectedSessionStorage 微软文档因为我们知道,依赖注入的生命周期是Singleton程序Scoped网页:刷新,url直接跳转都会重置。Transient路由C# Blazor 学习笔记(10):依赖注入但是没有一个和浏览器绑定的生命周期。即浏览器关闭才会退出。这个是后端无法获取的,因为后端根本不知道浏览器何时关闭。这个只能用浏览器自带的缓存。 阅读详情

相关推荐

使用 NTLite 来定制专属的官方 windows 镜像

移除掉不想要的一些自带的应用,比如 Xbox,office 啥的,这个就根据自己的实际需求来选择,备注基本都是有解释这个应用的作用。win 11 的右键展示不喜欢,更喜欢 win10 的,但是需要修改注册表,这里直接把下面的命令写到后期任务里面。NTLite 的自动保存会话功能会保留操作过的配置,是一个 xml 文件,可以在下次升级镜像版本的时候,导入配置。关闭 windows defender,不关会有这个提示,点是,就会跳到对应的界面。勾选创建 iso,配置 iso 镜像的名字,然后点开始。

以梦为马|越骑越傻 3331

POJ 1502 dijkstra()

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

1467

【知识点总结】电路原理 第一讲

大家好,从今天起,我将开始更新自上大学以来所学到的各种知识,之所以选择更新它们是因为最近我一直在收拾整理自己自上大学以来所收获到的各种知识,看着那厚厚一沓的书本心里不由得犯愁。如果我想找到特定的知识,那岂不是得翻到猴年马月。俗话说得好,下雨天打鞋子,闲着也是闲着,为此我设置一个专栏,将知识点一一分类总结,目的在于更好的整理所学的知识。本人学艺不精,有一些知识点地方可能存在瑕疵,希望各位大佬可以多多指教。以下是本篇文章正文内容虚断:一般通用性运算放大器的正反向输入端之间的电阻非常非常的大。

weixin_51130221的博客 4万+

POJ--1502 MPI Maelstrom

最近在复习最短路径。 dijkstra和最小生成树等等这些图论算法确实折磨了我一段时间啊。。 理解了就感觉好多了,最主要的是熟练。 这题其实是个裸的最短路径题目。可以用dijkstra,floyd这些算法,floyd的主要思想我是这样理解的,两点之间不断找中转点,直到遍历所有点。floyd还是有标准的模板可以套的,三个循环套就可。 dijkstra相比较更难理解,更偏向于贪心的思想吧。 这里用一道...

qq_43557402的博客 275

Label Studio + SAM2分割半自动标注与yolo11训练

Label Studio + SAM2分割半自动标注与yolo11训练

schFallingCloud 1408

【SpringBoot 4.x 第29节】Spring Security 7 入门:先理解认证和授权!

🏆 本文收录于 《滚雪球学 Spring Boot 4.x》 专栏。本专栏面向 有一定 Java 基础,但尚未系统学习 Spring Boot 的读者,采用“滚雪球式学习法”:先跑通、再理解、再重构、再上线,带你从第一个 Hello API 开始,逐步完成一个可部署、可监控、可扩展的后端项目。

**My Coding Family** 551

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

YOLO 系列专栏(二十九)YOLO26 × StarNet 轻量化涨点方案(CVPR 2024)轻量化、主干改进篇 | 星星卷积虽小,却蕴藏着巨大的高效潜力

StarNet 出自 CVPR 2024 轻量化主干网络工作,核心创新是,依靠逐元素乘法实现高阶特征融合,在几乎不增加参数量与 FLOPs 的前提下,大幅提升特征表达能力,天然适合等多任务统一建模。本文将 StarNet 完整替换 YOLO26 原有主干,保留 YOLO26 无 NMS 检测头与轻量化结构,实现,并提供。

qq_36130719的博客 409

poj-1502(MPI Maelstrom)

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

blackturtle的博客 622

1、基于改进3D卷积神经网络的阿尔茨海默病分类

本文提出了一种基于改进3D卷积神经网络的阿尔茨海默病(AD)分类方法,利用3D CNN对预处理后的T1加权MRI数据进行空间特征提取,并在VGG网络结构中引入类似ResNet的跳跃连接以缓解模型退化和过拟合问题。实验基于ADNI数据集,包含AD、MCI和NC三类样本,结果表明改进后的3D VGG模型在AD/NC、MCI/NC及多分类任务中均取得了优异性能,尤其在AD/MCI/NC分类中准确率达到98.50%,优于现有典型3D深度学习方法。研究验证了3D CNN在脑部疾病诊断中的有效性,并为AD的早期识别提供

kk1234的博客 89

后仿真中《SDF反标必懂连载篇》之 Negative Delay (理论篇)

今天,学习一下SDF文件中的负数延时问题。比如下面的图片中的SETUPHOLD 中的hold time 为负数。

那么菜的博客 2572

POJ 1502 MPI Maelstrom——dijkstra

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

hao_zong_yin的博客 531

【Flink】FlinkCDC获取mysql数据时间类型差8小时时区解决方案

​ 1、背景: 在我们使用FlinkCDC采集mysql数据的时候,日期类型是我们很常见的类型,但是FlinkCDC读取出来会和数据库的日期时间不一致,情况如下 FlinkCDC获取的数据中create_time字段1694597238000转换为时间戳2023-09-13 17:27:18,而数据库中原始数据如下,并没有到下午5点,这就导致了FlinkCDC读出来的时间和数据库中实际的时间不一致的情况,与数据库对比可以发现,这里的时间戳与数据库时间刚好相差了 8 个小时,在实际生产中这种情况是不

一杯咖啡半杯糖的博客 3854

POJ-1502 MPI Maelstrom (裸dijkstra算法)

POJ-1502 MPI Maelstrom (裸dijkstra模板)

crazymad的博客 483

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

POJ 1502 MPI Maelstrom 单源最短路Dijkstra

题意:有n个点,然后有一个矩阵为左下矩阵,A[i, j] = A[j, i] = k表示i到j的距离是k,路径是双向的。然后输出从点1出发达到所有顶点的最短路长度中最大的那个。想法:单源最短路,加上图中直接给出了矩阵,中规中矩的Dijkstra模板,主要是在证明算法正确性之后,很好的去理解算法的过程,和具体步骤的含义。用到一个atoi函数,表示将ACSII转化为int,用到的头文件#include...

猫ER 530

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

hdu 1370 中国剩余定理

首先介绍一下中国剩余定理,在寒假回来的飞机上曾经看过证明……但是看着看着就睡着了……先把方法写上,证明以后再补吧……(虽然也只会最简单的三个数的,还互素……) 中国剩余定理介绍了这样一个问题,有这样一个数x,x%a=a1,x%b=b1,x%c=c1,求这个数x。(a,b,c互素) 首先求出三个数的逆元a2,b2,c2,如,a的逆元a2就是b1*c1*a2%a==1; 于是这个

ctrss的博客 1515

假人有限元模型

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

poj2407欧拉函数模板

第一次接触欧拉函数,phi(x)为小于等于x且与x互质的数的个数……先介绍一些基本定理 1.定义在所有正整数上的函数成为算数函数。 2.一个算术函数f,如果对于两个互素整数m,n有f(nm)=f(n)*f(m)则称f为积性函数。如果对于任意两个正整数mn有f(nm)=f(n)*f(m)则称f为完全积性函数。 3.如果f是一个积性函数,则对于正整数n=p1^a1*p2^a2……(pi为素数),

ctrss的博客 1008

dinic网络流前向星写法

终于照着模板打了一遍前向星…… 虽然还不是太懂…… 直接上代码吧……依然是poj1273的题 #include #include #include #include #define M 400 int INF=10000001; using namespace std; struct node { int u,v,cap,next; }; node edge[M*M]; int

ctrss的博客 976

zoj 1196 Fast Food 变种区间dp

好吧,其实我觉得这个题在一开始想的时候与区间dp还是有点差别的……虽然写出来跟区间dp确实差不多 Fast Food Time Limit: 2 Seconds      Memory Limit: 65536 KB The fastfood chain McBurger owns several restaurants along a highway. Recently,

ctrss的博客 953

hdu 4355 Party All the Time 初识三分法

以前听到三分法的时候总是一脸懵逼,心想三分了怎么继续确定区间,三分的两个点又怎么确定?想破头也想不出来。 今天偷偷看了西工大某美女姐姐(好吧,虽然没见过,就这么叫吧)的博客,发现三分竟然是有特定条件的…… 先来说说三分法,据前人的研究,三分法适用于凹凸函数求它的凹凸点。与二分法不同的是三分法将mid点与r点的中间点也并入讨论,设其为mmid点。 显然,mmid>mid. 以凹函数为例子,求

ctrss的博客 914

cf676c Vasya and String 尺取法裸题

C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string o

ctrss的博客 910

CF 699D Fix a Tree 并查集

D. Fix a Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A tree is an undirected connected graph witho

ctrss的博客 779

poj1681Painter's Problem 增广矩阵消元法错误水过版

Painter's Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5519   Accepted: 2660 Description There is a square wall which is made of n*n small square

ctrss的博客 742

poj 1284欧拉函数求素数元根个数

Primitive Roots Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3601   Accepted: 2101 Description We say that integer x, 0 i mod p) | 1 <= i <= p-1 } is eq

ctrss的博客 688

poj 1222 EXTENDED LIGHTS OUT 增广矩阵消元法

EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8682   Accepted: 5624 Description In an extended version of the game Lights Out, is a puz

ctrss的博客 653

poj2773 欧拉函数+整除性质

Happy 2006 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 10751   Accepted: 3744 Description Two positive integers are said to be relatively prime to each o

ctrss的博客 652
上一篇: codeforces 585A - Gennady the Dentist(模拟)
下一篇: hdu1166线段树模板求和
ctrss
博客等级 码龄11年 1粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值