题目大意:

给你 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. ExtJS学习-----------Ext.String,ExtJS对javascript中的String的扩展

    关于ExtJS对javascript中的String的扩展,能够參考其帮助文档,文档下载地址:http://download.csdn.net/detail/z1137730824/7748893 以 ...

  2. Android自动化测试之Monkey工具

    前言:Android自动化测试工具.方法和框架,包括android测试框架.CTS.Monkey.Monkeyrunner.benchmark.test tool等. 一. 什么是MonkeyMonk ...

  3. Android为ListView的Item设置不同的布局

    MainActivity如下: package cc.testlistview; import java.util.ArrayList; import java.util.HashMap; impor ...

  4. PuTTY?Bash?Out了!!!终端应该这么玩~

    由于语言的障碍,国内一直存在一个问题,就是新技术引入太慢.比如PuTTY,其实已停止维护N久了,但大部分人却仍然在用(包括之前的我).比如Bash,明知有那么多的问题,却一直没有什么想法,似乎Linu ...

  5. android基础篇学习心得

    android技术中,线程.进程.JNI.IPC和各个小框架结构是基本功.在跟随高焕堂老师的android程序猿到架构师之路系列视频中 学习完基础篇之后,颇有些心得,记录下来. android开发就是 ...

  6. Android开发系列(一)Activity与Fragment获取屏幕获取屏幕像素的不同方式

    Activity中常用的获取屏幕像素代码: //获取屏幕像素相关信息 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getD ...

  7. codeforces 251A Points on Line(二分or单调队列)

    Description Little Petya likes points a lot. Recently his mom has presented him n points lying on th ...

  8. 【翻译】使用nginx作为反向代理服务器,uWSGI作为应用服务器来部署flask应用

    最近在看关于Docker和Nginx方面的内容,先于在Docker上开发以及部署python应用自然要先能够在本机上部署,其中找到一篇文章写的最为详细并且实验成功,所以在此翻译转载过来以备后需.[原文 ...

  9. Canvas transform浅析

    没有前奏,直接进入主题 transform调用方法: ctx.transform(a,b,c,d,e,f);如下 var ctx = document.getElementById("myC ...

  10. Swift - 07 - 布尔类型

    //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground& ...