POJ-1502-MPI Maelstrom-dijkstra+输入处理
``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 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
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+输入处理的更多相关文章
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- 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 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom
MPI Maelstrom Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) Total ...
- POJ 1502 MPI Maelstrom(最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4017 Accepted: 2412 Des ...
- POJ 1502 MPI Maelstrom (最短路)
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6044 Accepted: 3761 Des ...
- POJ - 1502 MPI Maelstrom 路径传输Dij+sscanf(字符串转数字)
MPI Maelstrom BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odys ...
- (简单) POJ 1502 MPI Maelstrom,Dijkstra。
Description BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odysse ...
- POJ 1502 MPI Maelstrom( Spfa, Floyd, Dijkstra)
题目大意: 给你 1到n , n个计算机进行数据传输, 问从1为起点传输到所有点的最短时间是多少, 其实就是算 1 到所有点的时间中最长的那个点. 然后是数据 给你一个n 代表有n个点, 然后给你一 ...
- POJ 1502 MPI Maelstrom(模板题——Floyd算法)
题目: BIT has recently taken delivery of their new supercomputer, a 32 processor Apollo Odyssey distri ...
随机推荐
- vue app外卖(5) 使用swiper 进行图片轮播
1.查看swiper 文档 https://www.swiper.com.cn/usage/index.html 2. 下载 npm install --save swiper 3.在页面引入 imp ...
- 阿里巴巴AI夺肝结节诊断两项世界冠军,至今无人超越
在澳门用人工智能预测流感趋势后,阿里巴巴还在继续探索如何用科技保障人类健康,这一次是更准确地测量肝结节. 12月28日消息,在全球LiTS(Liver Tumor Segmentation Chall ...
- zjoi 2008 树的统计——树链剖分
比较基础的一道树链剖分的题 大概还是得说说思路 树链剖分是将树剖成很多条链,比较常见的剖法是按儿子的size来剖分,剖分完后对于这课树的询问用线段树维护——比如求路径和的话——随着他们各自的链向上走, ...
- Delphi窗体重绘API
WinAPI: DrawFocusRect - 绘制焦点矩形 用SetTextColor()设置颜色 功能 设置指定设备环境(HDC)的字体颜色原型 WINGDIAPI COLORREF WINAPI ...
- NX二次开发-删除功能区工具栏UF_UI_remove_ribbon
NX9+VS2012 1.打开D:\Program Files\Siemens\NX 9.0\UGII\menus\ug_main.men 找到装配和PMI,在中间加上一段 TOGGLE_BUTTON ...
- [JZOJ 5600] Arg
题意:求最少LIS覆盖... 思路: 计算\(LIS\)时我们一般用\(dp\)表示到当先位置时以当前位置结尾的\(LIS\)最长长度. 那么这个数组保证单调不降,我们考虑二进制表示. 然后就是转移了 ...
- HDU5669
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 Portal 原题目描述在最下面. 给你n个点 ...
- Spring-Security (学习记录四)--配置权限过滤器,采用数据库方式获取权限
目录 1. 需要在spring-security.xml中配置验证过滤器,来取代spring-security.xml的默认过滤器 2. 配置securityMetadataSource,可以通过ur ...
- CSS3:CSS3 圆角
ylbtech-CSS3:CSS3 圆角 1.返回顶部 1. CSS3 圆角 CSS3 圆角 使用 CSS3 border-radius 属性,你可以给任何元素制作 "圆角". C ...
- RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers
how do I install all developer tools such as GNU GCC C/C++ compilers, make and others, after install ...