poj1502MPI Maelstrom

题目链接:http://poj.org/problem?id=1502

dijkstra。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<iostream>
 5 using namespace std;
 6 const int inf=0x3f3f3f3f;
 7 int pic[110][110];
 8 int vis[110];
 9 int dis[110];
10
11 int n;
12
13 void dijkstra()
14 {
15     for(int i=1;i<=n;i++){
16             dis[i]=inf;
17             vis[i]=0;
18     }
19     dis[1]=0;
20     for(int i=0;i<n;i++)
21     {
22         int x,m=inf;
23         for(int y=1;y<=n;y++) if(!vis[y]&&m>dis[y]) m=dis[x=y];
24         vis[x]=1;
25         for(int y=1;y<=n;y++) if(!vis[y]&&dis[y]>dis[x]+pic[x][y]) dis[y]=dis[x]+pic[x][y];
26     }
27 }
28
29 int tran(string s)
30 {
31     int len=s.length();
32     int d=0;
33     for(int i=0;i<len;i++)
34         d=d*10+(s[i]-‘0‘);
35     return d;
36 }
37
38 int main()
39 {
40
41 int d;
42     string s;
43     while(scanf("%d",&n)!=EOF)
44     {
45
46         for(int i=1;i<=n;i++)
47             for(int j=1;j<=n;j++)
48             pic[i][j]=(i==j?0:inf);
49         for(int i=2;i<=n;i++)
50             for(int j=1;j<i;j++)
51         {
52                 cin>>s;
53                 if(s=="x") continue;
54                 else
55                     {
56                     d=tran(s);
57                     pic[i][j]=pic[j][i]=d;
58                     }
59
60
61         }
62         dijkstra();
63         int ans=-1;
64         for(int i=2;i<=n;i++)
65             ans=max(ans,dis[i]);
66         printf("%d\n",ans);
67     }
68 }
时间: 2024-11-05 12:31:37

poj1502MPI Maelstrom的相关文章

poj 1502 MPI Maelstrom Dijkstra算法的简单运用 ,呵呵,,我估计有很多人都没看懂什么意思,我也看了很久

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5831   Accepted: 3621 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

POJ 1502 MPI Maelstrom (最短路)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6329   Accepted: 3925 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

MPI Maelstrom(poj1502)(迪杰斯特拉+atoi函数)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5637   Accepted: 3513 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

MPI Maelstrom(East Central North America 1996)(poj1502)

MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor

POJ 1052 MPI Maelstrom

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5547   Accepted: 3458 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

POJ 1502 MPI Maelstrom [最短路 Dijkstra]

传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierar

POJ 1502 MPI Maelstrom (Dijkstra 模板题)

MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5877   Accepted: 3654 Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchic

poj 1502 MPI Maelstrom(最短路)

poj 1502 MPI Maelstrom Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distributed shared memory machine with a hierarchical communication subsystem. Valentine McKee's research advisor, Jack Swige

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