POJ 1502 MPI Maelstrom最短路问题
来源:互联网 发布:java 二分法查找 编辑:程序博客网 时间:2024/06/04 19:37
题目大意:
有n个处理器,求一号处理器到所有处理器所需的时间总和。题目给出一个倒三角x表示两个处理器不能直接连通。数字表示传输时间。
题目思路:
先通过倒三角,求出图的邻接矩阵表示在裸dijkstra,程序如下:
# include<stdio.h># include<stdlib.h># include<string.h>int d[1010][1010],ans[1000000],t[10000];char s[10000];int main(){ int n,i,j,k,o,l,sum=0,m; char c; scanf("%d",&n); for(i=2;i<=n;i++) for(j=1;j<i;j++){ scanf("%s",&s);//用字符串读入每个数因为可能不是数字 if(s[0]=='x'){ d[i][j]=0;//s[0]=‘x’说明i,j不连接 d[j][i]=0; c=getchar(); continue; } m=0; l=strlen(s); for(k=0;k<l;k++){ m=m*10+s[k]-'0'; } d[i][j]=m; d[j][i]=m; //记得要将d[i][j]赋值为m c=getchar(); } for(i=1;i<=n;i++)ans[i]=1000000000;//dijkstra算法 ans[1]=0; for(i=1;i<=n;i++){ o=1000000000; for(j=1;j<=n;j++){ if(!t[j]&&ans[j]<o){ o=ans[j]; k=j; } } t[k]=1;//k为跳板 sum=ans[k]>sum?ans[k]:sum; for(j=1;j<=n;j++){ if(!t[j] && d[k][j] && ans[j]>ans[k]+d[k][j]){ ans[j]=ans[k]+d[k][j]; } } } printf("%d\n",sum); return 0; }
3 2
- POJ 1502 MPI Maelstrom最短路问题
- POJ 1502 MPI Maelstrom 最短路dijkstra
- poj 1502--MPI Maelstrom (最短路spfa)
- 【POJ】1502 MPI Maelstrom 最短路
- POJ 1502 MPI Maelstrom(最短路)
- POJ 1502 MPI Maelstrom 最短路
- POJ 1502MPI Maelstrom BFS最短路
- poj 1502 MPI Maelstrom(最短路)
- 最短路spfa POJ 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom【最短路】
- POJ 1502 MPI Maelstrom 最短路
- POJ-1502-MPI Maelstrom [最短路][Dijkstra]
- POJ 1502 MPI Maelstrom 【最短路(迪杰斯特拉)】
- MPI Maelstrom(最短路)
- POJ 1502 - MPI Maelstrom(单源最短路)
- POJ 1502 MPI Maelstrom(单源最短路)
- POJ 1502 - MPI Maelstrom(单源最短路)
- MPI Maelstrom poj 1502 单源最短路
- java变量及其作用域和调用方式
- redis主从模式
- AFNetworking 3.0迁移指南
- 遍历Map的四种方法
- shell脚本中数组的使用
- POJ 1502 MPI Maelstrom最短路问题
- 跨站请求伪造CSRF
- 初识Retrofit
- 博客虚拟主机的购买技巧
- Java (Abstract Method)抽象方法、(Abstract Class)抽象类
- C语言(数据类型)
- Redis集群搭建
- Redis概述
- android弹出框之Dialog