题目大意:

给你 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. 一起学android之怎样获取手机程序列表以及程序相关信息并启动指定程序 (26)

    效果图: 程序列表: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFpX3FpbmdfeHVfa29uZw==/font/5a6L5L2T/fonts ...

  2. RT: np - new sbt project generation made simple(r)

    np - new sbt project generation made simple(r) As pointed out in the comments by @0__ below, there's ...

  3. java.util.concurrent.atomic 类包详解

    java.util.concurrent包分成了三个部分,分别是java.util.concurrent.java.util.concurrent.atomic和java.util.concurren ...

  4. c#将Excel数据导入到数据库的实现代码(OleDb)

    sing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web ...

  5. Android开发手记(23) Notification

    有时候,我们需要应用程序在状态内显示一些通知信息,这时我们就需要使用Notification来完成这一工作.也许我们会想到以前经常使用的Toast来通知用户.虽然Notification与Toast都 ...

  6. 配置中的address不能重复

    <jaxws:endpoint  implementor="com.service.imp.UserServiceImpl" address="/user" ...

  7. MySQL 创建数据表

    MySQL 创建数据表 创建MySQL数据表需要以下信息: 表名 表字段名 定义每个表字段 语法 以下为创建MySQL数据表的SQL通用语法: CREATE TABLE table_name (col ...

  8. POJ 2230 (欧拉路)

    分析: 基础的欧拉路算法,变化在于要求每条边正向和反向各走一遍. 链式前向星构图,只要标记走过的单向边,边找边输出即可. code #include <iostream> #include ...

  9. 动态内存分配(new)和释放(delete)

    在之前我们所写过的程序中,所必需的内存空间的大小都是在程序执行之前就已经确定了.但如果我们需要内存大小为一个变量,其数值只有在程序运行时 (runtime)才能确定,例如有些情况下我们需要根据用户输入 ...

  10. 2.2.5 NIO.2 Path 和 Java 已有的 File 类

    NIO与IO交互 toPath() File -- Path toFile() Path -- File Demo: import java.io.File; import java.nio.file ...