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.''

Input

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.

Output

Your program should output the minimum communication time required to broadcast a message from the first processor to all the other processors.

Sample Input

5
50
30 5
100 20 50
10 x x 10

Sample Output

35

题意:
一个信息站需要往其他信息站传输信息。当一个站接受到信息之后马上向跟它相连的信息站传输信息。已知每两个相连信息站之间传输时间。
求:信息从第一个站传到每个站的最短时间。 
思路:将传输代价作为路径长度,即求第一个信息站到其它所有信息站最短路径的最大值。 题意比较难读懂,做题还用到了一个新函数atoi atoi用法:把字符串型转化成整型
头文件#include<stdlib.h>
注意:atoi()函数只能转换为整数,如果一定要写成浮点数的字符串,它会发生强制转换
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std; int main()
{
char ss[];
int aa=;
scanf("%s",&ss);
int dd=atoi(ss);
printf("**%d**\n",aa+dd);
return ;
}

测试数据输出


题目代码如下:
 #include<iostream>
#include<string.h>
#include<cmath>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<iomanip>
#define inf 0x3f3f3f3f
#define ios() std::ios::sync_with_stdio(false)
#define cin() cin.tie(0)
#define cout() cout.tie(0)
#define mem1(a) memset(a,0,sizeof(a))
#define mem2(b) memset(b,'\0',sizeof(b))
using namespace std; int a[][];
int dis[],book[];
int n;
char s[]; void init()
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i==j)
a[i][j]=;
else
a[i][j]=inf;
}
}
return ;
} int dijkstra()
{
mem1(book);
for(int i=; i<=n; i++)
dis[i]=a[][i];
book[]=;
int u;
for(int i=; i<=n-; i++)
{
int minn=inf;
for(int j=; j<=n; j++)
{
if(book[j]==&&dis[j]<minn)
{
minn=dis[j];
u=j;
}
}
book[u]=;
for(int k=; k<=n; k++)
{
if(a[u][k]<inf)
{
if(dis[k]>dis[u]+a[u][k])
{
dis[k]=dis[u]+a[u][k];
}
}
}
}
int maxx=-inf;
for(int i=; i<=n; i++)
maxx=max(maxx,dis[i]);
return maxx;
} int main()
{
// ios();
// cin();
// cout(); cin>>n;
init();
//?数组a开到110即可,x的ASCII是120,不会和其他重复
for(int i=; i<=n; i++)
{
for(int j=; j<i; j++)
{ // cin>>a[i][j];
// if(a[i][j]=='x')
// {
// a[i][j]=inf;
// }
// a[j][i]=a[i][j];
93 scanf("%s",s);
94 if(s[0]=='x')
95 a[i][j]=a[j][i]=inf;
96 else
97 a[i][j]=a[j][i]=atoi(s);//注意输入
}
}
cout<<dijkstra()<<endl;
return ;
}
 
一般写法,不用函数:(由于数据比较小,所以可以利用五行代码三层for循环来写)
 #include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f int e[][];
char a[]; int main()
{
int n;
scanf("%d",&n);
memset(e,,sizeof(e));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i==j)
e[i][j]=;
else
e[i][j]=inf;
}
} int sum;
for(int i=; i<=n; i++)
{
for(int j=; j<=i-; j++)
{
scanf("%s",a);
int len=strlen(a);
if(a[]=='x')
sum=inf;
else
{
sum=;
for(int k=; k<len; k++)
{
sum=sum*+(a[k]-'');
}
}
e[i][j]=e[j][i]=sum;
}
} for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
e[i][j]=min(e[i][j],e[i][k]+e[k][j]);
}
}
} int ans=-inf;
for(int i=;i<=n;i++)
ans=max(ans,e[][i]); printf("%d\n",ans);
return ;
}

 

POJ-1502-MPI Maelstrom-dijkstra+输入处理的更多相关文章

  1. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  2. 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 ...

  3. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  4. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

  5. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

  6. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  7. POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)

    MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...

  8. (简单) POJ 1502 MPI Maelstrom,Dijkstra。

    Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...

  9. POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)

    题目大意: 给你 1到n ,  n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...

  10. POJ 1502 MPI Maelstrom(模板题——Floyd算法)

    题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...

随机推荐

  1. leetcood学习笔记-107-二叉树的层次遍历二

    题目描述: 方法一: class Solution(object): def levelOrderBottom(self, root): """ :type root: ...

  2. QT install

    { https://www.bilibili.com/video/av18148008?from=search&seid=15361598961528715331 }

  3. 获取Delphi焦点所在的控件及通过控件名称访问控件

    方法一: Var I: Integer; Begin For I := To ComponentCount - Do //获取组件数量 Begin If Components[I] Is TWinCo ...

  4. bzoj1293题解

    [题意分析] 给你一条有n个点的数轴,每个点属于一个种类,总共有k个种类.求一段最短的线段,使对于每个种类,这段线段上有至少一个点属于它. [算法分析] 1.对于50%的数据,N≤10000 对于每一 ...

  5. 51nod 1627 瞬间移动(组合数学)

    传送门 解题思路 因为每次横纵坐标至少\(+1\),所以可以枚举走的步数,枚举走的步数\(i\)后剩下的就是把\(n-1\)与\(m-1\)划分成\(i\)个有序正整数相加,所以用隔板法,\(ans= ...

  6. Python 查看QQ状态

    import requests """ 该程序依赖于QQ的端口程序 返回数据:String,Y = 在线:N = 离线:E = QQ号码错误:A = 商业用户验证失败:V ...

  7. log4j架构

    Log4j API设计为分层结构,其中每一层提供了不同的对象,对象执行不同的任务.这使得设计灵活,根据将来需要来扩展. 有两种类型可用在Log4j的框架对象. 核心对象: 框架的强制对象和框架的使用. ...

  8. 《转》python

    转自http://www.cnblogs.com/BeginMan/archive/2013/06/03/3114974.html 1.print语句调用str()函数显示,交互式解释器调用repr( ...

  9. Nginx配置web服务

    Nginx配置虚拟主机 虚拟主机概述 所谓虚拟主机,在web服务里就是一个独立的网站站点,这个站点对应独立的域名(也可以是IP或者端口),具有独立的程序及资源目录,可以独立的对外提供服务,继而给用户访 ...

  10. 2008年国外50个最佳CSS设计欣赏

    这50个CSS网站是由WebDesignerWall评选出来的,很具参考价值.我们在欣赏的同时,也能从中吸取很多灵感,也能从它们的源代码中学习更高级的CSS技术.今年,越来越多的设计师开始使用超大的背 ...