题目大意:

给你 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. setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delete.的问题

    今天弄ios的sqlite数据库,程序写完后编译发现一个奇怪的问题,错误信息也不提示行号,只有如下信息: 一遍遍的查找代码也没有发现啥问题,后来在storyboard中找到了该错误的原因 原来是一个按 ...

  2. linux (ubuntu) 下设置 tomcat 随系统自动启动

    网上说的有很多, 我只记录一种 1. 切换到 /etc/init.d/ 目录下 2. sudo vim tomcat 3. 在打开的文件里写入以下内容 #!/bin/sh # chkconfig: # ...

  3. 新版本ButterKnife的配置

    新版本的ButterKnife的添加方式发生了变化,然后摸索着记录了一下. 按照ButterKnife的官网描述,使用ButterKnife需要在Gradle中添加如下依赖: compile 'com ...

  4. .NET aspx页面中的按钮无法响应事件

    原因只有一个,页面中存在多个form标签.按Ctrl+F,找到多余的删掉即可

  5. HDU5319

    题意:给一个矩形染色,顺笔表示红色,逆笔表示蓝色(既一捺和一丿),交叉表示绿色,然后给你一个图,问你用多少笔能画出这个图来. 思路:对这个图直接模拟即可,如果点i,j坐标为红色,那么判断上一个路径点是 ...

  6. 写代码要注意细节,无谓的找前台bug

    <input type="checkbox" name="ckb" value="'+value[0]+'">'真的感觉小细节真 ...

  7. 程序里面的system.out.println()输出到其他位置,不输出到tomcat控制台。

    设置startup.bat: call "%EXECUTABLE%" run %CMD_LINE_ARGS% >> ..\logs\kongzitai.txt 将sys ...

  8. [C++] namespace相关语法

    本段测试代码包括如下内容: (1) 如何访问namespace中声明的名称:(2) namespace导致的相关冲突:(3) namespace可嵌套:(4) 可以在namespace中使用using ...

  9. Android JNI 之 环境安装

    在配置环境之前,我们得了解 JNI 和NDK JNI JNI是Java Native Interface的缩写,中文为JAVA本地调用.它提供了若干的API实现了和Java和其他语言的通信(主要是C& ...

  10. Vim中安装delimitMate,auto-pairs插件不能输入中文问题

    在安装了delimitMate插件之后发现不能正常使用中文输入了,输入法系统是ibus. 解决办法是在ibus的设置中的“在应用程序中使用内嵌编辑模式”这一项去除就可以正常输入中文了,看来可能是ibu ...