博客
关于我
MPI Maelstrom POJ - 1502
阅读量:280 次
发布时间:2019-03-01

本文共 1509 字,大约阅读时间需要 5 分钟。

题意:大致意思是1到其他点的最短距离中最大的那个距离是多少。

可以用的算法:Floyd,Dijkstar,Bellman-Ford,Spfa
个人这道题用了Spfa,因为上道题用了Spfa,不想重写了,嘿嘿嘿

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define PI acos(-1)#define mes(x,y) memset(x,y,sizeof(x))#define lp pair
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)using namespace std;const ll inf = 10000000000000005;ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;string s1, s2, s;struct node { ll end, len;; node(ll x, ll y) :end(x), len(y){ }};vector
>v;ll dis[110];ll ismove[110];ll StrTurnNum(string s) { sum = 0;ll i = 0; while (i < s.length())sum = (ll(s[i++] - '0'))+sum* 10; return sum;}ll Spfa(ll beginkind) { mes(dis, inf); mes(ismove, 0); queue
que; dis[beginkind] = 0; que.push(beginkind); while (!que.empty()) { t = que.front(); que.pop(); ismove[t] = 0; for (i = 0; i < v[t].size(); i++) { if (dis[v[t][i].end] > dis[t] + v[t][i].len) { dis[v[t][i].end] = dis[t] + v[t][i].len; if (ismove[v[t][i].end] == 0) que.push(v[t][i].end); ismove[v[t][i].end] = 1; } } } for (i = 2, j = dis[1]; i <= n; i++)j = max(j, dis[i]); return j;}int main() { cin >> n; for (i = 2,v.resize(n+1); i <= n; i++) { for (j = 1; j < i; j++) { cin >> s; if (s == "x")continue; else { v[i].push_back(node(j, StrTurnNum(s))); v[j].push_back(node(i, StrTurnNum(s))); } } } cout << Spfa(1) << endl; return 0;}

转载地址:http://qmvo.baihongyu.com/

你可能感兴趣的文章
Mysql_Postgresql中_geometry数据操作_st_astext_GeomFromEWKT函数_在java中转换geometry的16进制数据---PostgreSQL工作笔记007
查看>>
mysql_real_connect 参数注意
查看>>
mysql_secure_installation初始化数据库报Access denied
查看>>
MySQL_西安11月销售昨日未上架的产品_20161212
查看>>
Mysql——深入浅出InnoDB底层原理
查看>>
MySQL“被动”性能优化汇总
查看>>
MySQL、HBase 和 Elasticsearch:特点与区别详解
查看>>
MySQL、Redis高频面试题汇总
查看>>
MYSQL、SQL Server、Oracle数据库排序空值null问题及其解决办法
查看>>
mysql一个字段为空时使用另一个字段排序
查看>>
MySQL一个表A中多个字段关联了表B的ID,如何关联查询?
查看>>
MYSQL一直显示正在启动
查看>>
MySQL一站到底!华为首发MySQL进阶宝典,基础+优化+源码+架构+实战五飞
查看>>
MySQL万字总结!超详细!
查看>>
Mysql下载以及安装(新手入门,超详细)
查看>>
MySQL不会性能调优?看看这份清华架构师编写的MySQL性能优化手册吧
查看>>
MySQL不同字符集及排序规则详解:业务场景下的最佳选
查看>>
Mysql不同官方版本对比
查看>>
MySQL与Informix数据库中的同义表创建:深入解析与比较
查看>>
mysql与mem_细说 MySQL 之 MEM_ROOT
查看>>