题目大意:

给你 1到n ,  n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点。

然后是数据

给你一个n 代表有n个点, 然后给你一个邻接矩阵, 只有一半,另一半自己补

下面是练习的代码。 分别用了Floyd 和 Dijkstra 还有 Spfa(邻接矩阵版)

#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define INF 0xfffffff
#define maxn 1006
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
int n;
int maps[maxn][maxn], dist[maxn];
bool vis[maxn]; int Dijkstra()
{
dist[] = ;
for(int i=; i<=n; i++)
{
int index, Min = INF; for(int j=; j<=n; j++)
{
if(!vis[j] && Min > dist[j])
index = j, Min = dist[j];
} vis[index] = true; for(int j=; j<=n; j++)
{
if( !vis[j] )
dist[j] = min(dist[j], dist[index] + maps[index][j]);
}
}
int Max = ;
for(int i=; i<=n; i++)
Max = max(Max, dist[i]); return Max;
}
void ReadMaps()
{
char str[]; memset(vis,false,sizeof(vis)); for(int i=; i<=n; i++)
{
dist[i] = INF;
maps[i][i] = ;
for(int j=; j<i; j++)
{
scanf("%s", str); if(strcmp(str,"x") == )
maps[i][j] = INF;
else
sscanf(str,"%d", &maps[i][j]); maps[j][i] = maps[i][j];
}
}
}
int main()
{
while(cin >> n)
{
ReadMaps(); int ans = Dijkstra(); cout << ans << endl;
}
return ;
}
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define INF 0xfffffff
#define maxn 120 int G[maxn][maxn];
int n;
void Floyd();
void Slove();
void Init(); int main()
{
char str[];
int a;
while(cin>> n)
{
Init(); for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
scanf("%s", str); if(str[] == 'x')
a = INF;
else
sscanf(str,"%d", &a); G[i][j] = G[j][i] = a;
}
} Slove();
} return ;
}
void Floyd()
{
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
}
}
}
}
void Slove()
{
Floyd();
int Max = ;
for(int i=; i<=n; i++)
{
Max = max(Max, G[][i]);
} cout << Max << endl;
}
void Init()
{
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
G[i][j] = G[j][i] = INF;
G[i][i] = ;
}
}
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define INF 0xfffffff
#define maxn 120 int G[maxn][maxn];
int n, dist[maxn], vis[maxn];
void Spaf();
void Slove();
void Init(); int main()
{
char str[];
int a;
while(cin>> n)
{
Init(); for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{
scanf("%s", str); if(str[] == 'x')
a = INF;
else
sscanf(str,"%d", &a); G[i][j] = G[j][i] = a;
}
} Slove();
} return ;
}
void Spfa()
{
int p;
queue<int> Q;
Q.push();
dist[] = ;
while( !Q.empty() )
{
p = Q.front();
Q.pop();
vis[p] = false;
for(int i=; i<=n; i++)
{
if(dist[i] > dist[p] + G[p][i])
{
dist[i] = dist[p] + G[p][i]; if( !vis[i] )
{
Q.push(i);
vis[i] = true;
}
}
}
}
}
void Slove()
{
Spfa();
int Max = ;
for(int i=; i<=n; i++)
{
Max = max(Max, dist[i]);
} cout << Max << endl;
}
void Init()
{
for(int i=; i<=n; i++)
{
dist[i] = INF, vis[i] = false;
for(int j=; j<i; j++)
G[i][j] = G[j][i] = INF;
G[i][i] = ;
}
}

POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)的更多相关文章

  1. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  2. POJ 1502 MPI Maelstrom【floyd】

    题目大意:求点1到所有点最短路径的最大值 思路:水题,单源最短路,网上解题清一色dijkstra,但是点数小于100显然floyd更简洁嘛 #include<cstdio> #includ ...

  3. POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)

    POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...

  4. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  5. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  6. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  7. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

  8. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  9. (简单) POJ 1502 MPI Maelstrom,Dijkstra。

    Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...

随机推荐

  1. pat 1060. Are They Equal (25)

    题目意思直接,要求将两个数转为科学计数法表示,然后比较是否相同  不过有精度要求 /* test 6 3 0.00 00.00 test 3 3 0.1 0.001 0.001=0.1*10^-2 p ...

  2. [Angular 2] Passing data to components with 'properties'

    Besides @Input(), we can also use properties on the @Component, to pass the data. import {Component, ...

  3. Enterprise Architect使用教程

    一.Enterprise Architect简介 Enterprise Architect是一个对于软件系统开发有着极好支持的CASE软件(Computer Aided Software Engine ...

  4. Linux禁止ping服务

    ping是一个通信协议,是ip协议的一部分,tcp/ip 协议的一部分.利用它可以检查网络是否能够连通,用好它可以很好地帮助我们分析判定网络故障.应用格式为:Ping IP地址.但服务启用ping有时 ...

  5. 使用ImageView

    @property (strong, nonatomic) UIPopoverController *pop; //选取图片- (IBAction)selectImage:(UIButton *)se ...

  6. ASP.NET-FineUI开发实践-14

    以前写过一个表格自动补全,改下,就出现了部分级联修改.测试版本4.1.1 共享下JS,ext-part2.js       后台再来个得到数据的方法就可以了.   1.方法还是删除+插入,主要在  i ...

  7. 让VC编译出来的程序不依赖于msvcr80.dll/msvcr90.dll/msvcr100.dll等文件

    ---转载:http://hi.baidu.com/liu_haitao/item/e2157ac3a3c32a0bc610b253 让VC编译出来的程序不依赖于msvcr80.dll/msvcr90 ...

  8. Sqlserver2005手动备份远程数据库到本地数据库方法

    1,在本地数据库中新建一个数据库名,如local 选中local,鼠标右键,任务,导入数据 2下一步: 注意:服务器名称写远程连接的主机的IP, 数据库选中你要备份的远程数据库. 3下一步: 注意:服 ...

  9. 安装PHP过程中,make步骤报错:(集合网络上各种解决方法)

    安装PHP过程中,make步骤报错:(集合网络上各种解决方法) (1)-liconv -o sapi/fpm/php-fpm /usr/bin/ld: cannot find -liconv coll ...

  10. 重温web服务器--细说Tomcat服务器

    从大学开始接触java web的开发时就开始使用tomcat部署web项目,对它的理解仅仅停留在"这是个开源免费的servlet容器"的阶段,后来也接触了一些tomcat的体系,原 ...