POJ1502 MPI Maelstrom Dijkstra
题意
给出图,从点1出发,求到最后一个点的时间。
思路
单源最短路,没什么好说的。注意读入的时候的技巧。
代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int n;
int edge[maxn][maxn];
int d[maxn];
bool used[maxn];
void dijkstra(int s)
{
d[s] = 0;
while(true) {
int v = -1;
for(int i = 1 ; i <= n ; i ++) {
if(!used[i]) {
if(v == -1 || d[i] < d[v]) v = i;
}
}
if(v == -1) break;
used[v] = true;
for(int i = 1 ; i <= n ; i ++) {
d[i] = min(d[i],d[v]+edge[v][i]);
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
fill(d,d+maxn,INF);
memset(used,false,sizeof(used));
for(int i = 0 ; i < maxn ; i ++) {
fill(edge[i],edge[i]+maxn,INF);
edge[i][i] = 0;
}
scanf("%d",&n);
for(int i = 2 ; i <= n ; i ++) {
for(int j = 1 ; j < i ; j ++) {
int tmp;
char getit;
if(scanf("%d",&tmp))
edge[i][j] = edge[j][i] = tmp;
else scanf("%c",&getit);
}
}
dijkstra(1);
int ma = d[1];
for(int i = 2 ; i <= n ; i ++) {
ma = max(d[i],ma);
}
cout << ma << endl;
return 0;
}
POJ1502 MPI Maelstrom Dijkstra的更多相关文章
- POJ-1502 MPI Maelstrom 迪杰斯特拉+题解
POJ-1502 MPI Maelstrom 迪杰斯特拉+题解 题意 题意:信息传输,总共有n个传输机,先要从1号传输机向其余n-1个传输机传输数据,传输需要时间,给出一个严格的下三角(其实就是对角线 ...
- POJ 1502:MPI Maelstrom Dijkstra模板题
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6499 Accepted: 4036 Des ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- MPI Maelstrom(Dijkstra)
http://poj.org/problem?id=1502 刷一道模板题稳定一下心情... Dijkstra求单源最短路,就是输入的时候注意下,是按下三角输入的(无向图),输入字符x表示i与j不通. ...
- POJ1502: MPI Maelstrom
红果果的dijstra算法应用,这里采用邻接表存储图 小插曲:while(scanf("%d",&n))提交时内存超限,改成while(scanf("%d&quo ...
- poj1502 MPI Maelstrom(单源最短路)
题意:表面乍一看output是输出最小值,但仔细研究可以发现,这个最小值是从点1到所有点所花时间的最小值,其实是访问这些节点中的最大值,因为只有访问了最长时间的那个点才算访问了所有点.所以求最短路之后 ...
- MPI Maelstrom(East Central North America 1996)(poj1502)
MPI Maelstrom 总时间限制: 1000ms 内存限制: 65536kB 描述 BIT has recently taken delivery of their new supercom ...
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- 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 ...
随机推荐
- Eclipse Maven 创建Hello World Web项目
通过Eclipse创建Maven Web项目的简单步骤 先决条件 (Prerequisites) 1,JDK environment, 具体的安装JDK的步骤和环境配置一般网上都有,这里就不在赘述. ...
- [HTML5] Inlining images with SVG and data URIs
The main reason you want to do I"nlining images with SVG and data URIs" is to reduce http ...
- 设计模式入门之代理模式Proxy
//代理模式定义:为其它对象提供一种代理以控制对这个对象的訪问 //实例:鉴于书中给出的样例不太好.并且有些疑问,所以直接用保护代理作为实例 //要求,一旦订单被创建,仅仅有订单的创建人才干够改动订单 ...
- JStorm之Topology调度
topology在服务端提交过程中,会经过一系列的验证和初始化:TP结构校验.创建本地文件夹并拷贝序列化文件jar包.生成znode用于存放TP和task等信息,最后一步才进行任务分配.例如以下图 ...
- Thrift源代码分析(七)-- TServerserver分析
Thrift採用了TServer来作为server的抽象,提供了多种类型的server实现.用TServerTransport作为server的Acceptor抽象,来监听端口.创建clientSoc ...
- WPF获取和设置鼠标位置与progressbar的使用方法
一.WPF 中获取和设置鼠标位置 方法一:WPF方法 Point p = Mouse.GetPosition(e.Source as FrameworkElement); Point p = (e.S ...
- ES设置查询的相似度算法
similarity Elasticsearch allows you to configure a scoring algorithm or similarity per field. The si ...
- 关于linux下QIODevice类进行读取的几个方法的理解
Qt中对读写设备的支持力度很大,其都继承与QIODevice类,其中有几个方法是非常值得注意的,不管是在用原始的serial port进行通信还是使用网络的TCP/IP 或者UDP或者HTTP等协议时 ...
- TensorFlow训练MNIST报错ResourceExhaustedError
title: TensorFlow训练MNIST报错ResourceExhaustedError date: 2018-04-01 12:35:44 categories: deep learning ...
- pic16F1938
1.中断自动保存寄存器:W.STATUS.BSR.FSR和PCLATH,而且如果中断中需要改变这些寄存器,在Bank31中修改这些寄存器的影子寄存器即可. 2.RAM有1024字节,分为N个bank, ...