POJ-1502(基本dijikstra算法)
MPI Maelstrom
POJ-1502
- 这题是求最短路,但是因为一开始看错题目,导致我去使用prime算法求最小生成树
- 题意是指一台机器发出信息后,还可以向其他的机器发送信息,所以不能使用prime算法。尽管两者区别很小
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int INF=0x3f3f3f3f;
int n;
int map[101][101];
bool used[101];
int d[101];//mincost[i]表示i到已知集合最小值
void dijkstra(){
for(int i=0;i<n;i++){
d[i]=INF;
used[i]=0;
}
d[0]=0;
int ans=0;
for(int i=0;i<n;i++){
int v=-1;
for(int j=0;j<n;j++){
if(!used[j]&&(v==-1||d[j]<d[v])){
v=j;
}
}
if(v==-1)
break;
used[v]=1;
//ans+=mincost[v];
for(int u=0;u<n;u++){
//d[u]=min(d[u],map[v][u]);//这里和djikstra算法有区别
d[u]=min(d[u],d[v]+map[v][u]);
}
}
//return ans;
}
int cal(string s){
int ans=0;
for(int i=0;i<s.length();i++){
ans=ans*10+s[i]-'0';
}
return ans;
}
int main(){
cin>>n;
string ch;
memset(map,0,sizeof(map));
for(int i=1;i<n;i++){
for(int j=0;j<i;j++){
cin>>ch;
if(ch=="x"){
map[i][j]=INF;
map[j][i]=INF;
}else{
int ans=cal(ch);
map[i][j]=ans;
map[j][i]=ans;
}
}
}
int ans=0;
dijkstra();
for(int i=1;i<n;i++){
ans=max(ans,d[i]);
}
cout<<ans<<endl;
//system("pause");
return 0;
}
POJ-1502(基本dijikstra算法)的更多相关文章
- 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 ...
- POJ-3159(差分约束+Dijikstra算法+Vector优化+向前星优化+java快速输入输出)
Candies POJ-3159 这里是图论的一个应用,也就是差分约束.通过差分约束变换出一个图,再使用Dijikstra算法的链表优化形式而不是vector形式(否则超时). #include< ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
- POJ 矩阵相乘 (随机化算法-舍伍德(Sherwood))
周三的算法课,主要讲了随机化算法,介绍了拉斯维加斯算法,简单的理解了为什么要用随机化算法,随机化算法有什么好处. 在处理8皇后问题的时候,穷举法是最费时的,回朔比穷举好点,而当数据量比较大的时候,如1 ...
- poj 1502 最短路+坑爹题意
链接:http://poj.org/problem?id=1502 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Subm ...
- poj - 3259 Wormholes (bellman-ford算法求最短路)
http://poj.org/problem?id=3259 农夫john发现了一些虫洞,虫洞是一种在你到达虫洞之前把你送回目的地的一种方式,FJ的每个农场,由n块土地(编号为1-n),M 条路,和W ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- POJ 1258 Agri-Net(Prim算法求解MST)
题目链接: http://poj.org/problem?id=1258 Description Farmer John has been elected mayor of his town! One ...
- POJ 1861 Network (Kruskal算法+输出的最小生成树里最长的边==最后加入生成树的边权 *【模板】)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14021 Accepted: 5484 Specia ...
随机推荐
- hdu3461 Code Lock
Problem Description A lock you use has a code system to be opened instead of a key. The lock contain ...
- Codeforces Round #555 (Div. 3) E. Minimum Array (贪心,二分,set)
题意:给你两个长度为\(n\)的数组\(a\)和\(b\),元素值在\([0,n-1]\),可以对\(b\)数组的元素任意排序,求新数组\(c\),满足\(c_i=(a_i+b_i)\ mod\ n\ ...
- C++快读
写在前面: 一个小专题 完全非原创,不知道原来是谁提出的 诈尸 http://thepingaslord.deviantart.com/art/The-Evening-Prior-312446336 ...
- Codeforces #620 div2 B
题目: Returning back to problem solving, Gildong is now studying about palindromes. He learned that a ...
- hdu5402 Travelling Salesman Problem
Problem Description Teacher Mai is in a maze with n rows and m columns. There is a non-negative numb ...
- Codeforces Round #643 (Div. 2) C. Count Triangles (数学公式)
题意:给你四个正整数\(A,B,C,D\),且\(A\le B\le C \le D\),有\(A\le x\le B\le y\le C \le z\le D\),求最多有多少组\((x,y,z)\ ...
- AWS注册到连接
1. 注册AWS账号 https://www.cnblogs.com/cmt/p/13912814.html 2.注册完成之后,选择实例 Ubuntu,下载xxx.pem文件,查看实例得到ip 比如我 ...
- 获取csc.exe路径
using System.Runtime.InteropServices; var frameworkPath = RuntimeEnvironment.GetRuntimeDirectory(); ...
- 国产网络损伤仪SandStorm -- 为什么数据流还是走Bypass链路?
如果你在使用网络损伤仪SandStorm测试移动互联网的应用程序或者在仿真所谓"弱网测试"的时候,发现所有的数据流还是在走Bypass链路,并没有预期地走自己创建的仿真链路,那么你 ...
- 爬虫入门四 re
title: 爬虫入门四 re date: 2020-03-14 16:49:00 categories: python tags: crawler 正则表达式与re库 1 正则表达式简介 编译原理学 ...