POJ 3660 Cow Contest (最短路dijkstra)
MPI Maelstrom
题目链接:
http://acm.hust.edu.cn/vjudge/contest/122685#problem/G
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 Swigert, has asked her to benchmark the new system.
``Since the Apollo is a distributed shared memory machine, memory access and communication times are not uniform,'' Valentine told Swigert. ``Communication is fast between processors that share the same memory subsystem, but it is slower between processors that are not on the same subsystem. Communication between the Apollo and machines in our lab is slower yet.''
``How is Apollo's port of the Message Passing Interface (MPI) working out?'' Swigert asked.
Not so well,'' Valentine replied.
To do a broadcast of a message from one processor to all the other n-1 processors, they just do a sequence of n-1 sends. That really serializes things and kills the performance.''
``Is there anything you can do to fix that?''
Yes,'' smiled Valentine.
There is. Once the first processor has sent the message to another, those two can then send messages to two other hosts at the same time. Then there will be four hosts that can send, and so on.''
``Ah, so you can do the broadcast as a binary tree!''
``Not really a binary tree -- there are some particular features of our network that we should exploit. The interface cards we have allow each processor to simultaneously send messages to any number of the other processors connected to it. However, the messages don't necessarily arrive at the destinations at the same time -- there is a communication cost involved. In general, we need to take into account the communication costs for each link in our network topologies and plan accordingly to minimize the total time required to do a broadcast.''
</big>
##Input
<big>
The input will describe the topology of a network connecting n processors. The first line of the input will be n, the number of processors, such that 1 <= n <= 100.
The rest of the input defines an adjacency matrix, A. The adjacency matrix is square and of size n x n. Each of its entries will be either an integer or the character x. The value of A(i,j) indicates the expense of sending a message directly from node i to node j. A value of x for A(i,j) indicates that a message cannot be sent directly from node i to node j.
Note that for a node to send a message to itself does not require network communication, so A(i,i) = 0 for 1 <= i <= n. Also, you may assume that the network is undirected (messages can go in either direction with equal overhead), so that A(i,j) = A(j,i). Thus only the entries on the (strictly) lower triangular portion of A will be supplied.
The input to your program will be the lower triangular section of A. That is, the second line of input will contain one entry, A(2,1). The next line will contain two entries, A(3,1) and A(3,2), and so on.
</big>
##Output
<big>
Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.
</big>
##Sample Input
<big>
5
50
30 5
100 20 50
10 x x 10
</big>
##Sample Output
<big>
35
</big>
##Hint
<big>
</big>
<br/>
##题意:
<big>
给出N个点,求#1到其他点的最短路径中的最大值.
</big>
<br/>
##题解:
<big>
由于点之间的关系用矩阵给出.
所以直接用dijkstra的邻接数组形式实现即可.
</big>
<br/>
##代码:
``` cpp
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#define LL long long
#define eps 1e-8
#define maxn 120
#define inf 0x3f3f3f3f
#define IN freopen("in.txt","r",stdin);
using namespace std;
int n,m;
int value[maxn][maxn];
int dis[maxn];
int pre[maxn];
bool vis[maxn];
void dijkstra(int s) {
memset(vis, 0, sizeof(vis));
memset(pre, -1, sizeof(pre));
for(int i=1; i<=n; i++) dis[i] = inf;
dis[s] = 0;
for(int i=1; i<=n; i++) {
int p, mindis = inf;
for(int j=1; j<=n; j++) {
if(!vis[j] && dis[j]<mindis)
mindis = dis[p=j];
}
vis[p] = 1;
for(int j=1; j<=n; j++) {
//if(dis[p]+value[p][j] < dis[j]) dis[j] = dis[p] + value[p][j];
if(dis[j] > dis[p]+value[p][j]) {
dis[j] = dis[p] + value[p][j];
pre[j] = p;
}
}
}
}
int main(int argc, char const *argv[])
{
//IN;
while(scanf("%d", &n) != EOF)
{
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
value[i][j] = value[j][i] = inf;
for(int i=2; i<=n; i++)
for(int j=1; j<i; j++) {
int x;
if(scanf("%d",&x)) value[i][j] = value[j][i] = x;
else scanf("x");
}
dijkstra(1);
int ans = -1;
for(int i=2; i<=n; i++)
ans = max(ans, dis[i]);
printf("%d\n", ans);
}
return 0;
}
POJ 3660 Cow Contest (最短路dijkstra)的更多相关文章
- POJ 3660 Cow Contest ( 最短路松弛思想应用 && Floyd求传递闭包 )
题意 : 给出 N 头奶牛在比赛的结果,问你最多的能根据给出结果确定其名次的奶牛头数.结果给出的形式为 A B 代表在比赛当中 A 战胜了 B 分析 : 对于一头奶牛来说,如果我们能确定其他 N - ...
- POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包)
POJ 3660 Cow Contest / HUST 1037 Cow Contest / HRBUST 1018 Cow Contest(图论,传递闭包) Description N (1 ≤ N ...
- POJ 3660 Cow Contest
题目链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- POJ 3660—— Cow Contest——————【Floyd传递闭包】
Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ - 3660 Cow Contest 传递闭包floyed算法
Cow Contest POJ - 3660 :http://poj.org/problem?id=3660 参考:https://www.cnblogs.com/kuangbin/p/31408 ...
- POJ 3660 Cow Contest (floyd求联通关系)
Cow Contest 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/H Description N (1 ≤ N ≤ 100) ...
- POJ 3660 Cow Contest(传递闭包floyed算法)
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5989 Accepted: 3234 Descr ...
- POJ 3660 Cow Contest(Floyd求传递闭包(可达矩阵))
Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16341 Accepted: 9146 Desc ...
- ACM: POJ 3660 Cow Contest - Floyd算法
链接 Cow Contest Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Descri ...
随机推荐
- vim编程 插入 保存不退出 保存退出 退出不保存 另存为其他文件名 保存覆盖现有文件
---恢复内容开始--- 在xshell里写代码,如果需要编辑代码,可以输入 vim+ xxx.py ,进入vim编辑界面 这里的xxx.py表示 python的存储文件,后缀名是.py. 1. ...
- OEM - emctl resetTZ agent 设置时区
[oracle@redhat4 config]$ cd $ORACLE_HOME/redhat4.7_orcl/sysman/config [oracle@redhat4 config]$ pwd/u ...
- 关于<img>标签与文字垂直居中
要让左边的图片与后面的文字居中,如下效果 HTML代码: <img class="iconCls" alt="最新客户端" src="${bas ...
- Java 知识点:序列化
首先明确一点:默认的序列化方法速度很慢,因为需要对整个对象和他的类都进行保存,因此我们建议自定义序列化格式. ObjectInputStream和ObjectOutputStream 用途 Objec ...
- UVA 575 Skew Binary (水)
题意:根据这种进制的算法,例如,给你一个左式,要求推出右式.(其实右式就是一个十进制数,根据这种进位的方法来转成特殊进制的数.) 思路:观察转换特点,有点类似于二进制,但是其在后面还减一了.比如25- ...
- HelloX操作系统与中国移动OneNET物联网平台成功完成对接
HelloX成功与中国移动物联网平台对接 经过HelloX项目组同仁的努力,尤其是Tywin(@飓风)的努力下,HelloX最新版本V1.78已成功与中国移动OneNET(open.iot.10086 ...
- CocoaPods一个Objective-C第三方库的管理利器
转:http://blog.csdn.net/totogo2010/article/details/8198694 介绍: 开发应用的时候第三方的库是不可缺少的,能提高开发的效率. 一些经常用到的库, ...
- mysql5.6子查询的优化
https://dev.mysql.com/doc/refman/5.6/en/subquery-optimization.html Semi-join in MySQL 5.6 MySQL 5. ...
- [Everyday Mathematics]20150209
设 $f$ 在区间 $I$ 上三阶可导, $f'\neq 0$, 则可定义 $f$ 的 Schwarz 导数: $$\bex S(f,x)=\frac{f'''(x)}{f'(x)}-\frac{3} ...
- oracle-Oracle试题
ylbtech-doc:oracle-Oracle试题 oracle-Oracle试题 1.A,返回顶部 01.{Oracle题目}你判断下面语句,有什么作用?(选择1项) GRANT upd ...