POJ 1125(最短路)
来源:互联网 发布:mysql front 破解版 编辑:程序博客网 时间:2024/05/16 06:21
如果这题不会,可能大多数跟我一样都是题难以理解的,我大致说下题意
题意:
题目大意:输入一个整数M,表示有M个股票经纪人,在接下来的M行,第i行(0<i<m)开头输入一个N,表示有N组数据,(aj,bj (1<=j<=n,))。bj表示第i号股票经纪人与aj号股票经纪人的联系时间。得出一个股票经纪人的编号,要求与其它股票经纪人联系的时间之和最短,而且得出其中联系时间最长的那个时间,并输出。
解题思路:题意很简单,解决的方法也很简单,完全是一个联系floyd算法的初级题。只需要用floyd算出每个股票经纪人与其它人的最小联系时间即可。(当然,可以通过通知甲,然后再通过甲去通知乙。)
我直接就帖代码了#include<cstdio>#include<cstring>#include<iostream>#define N 105#define inf 10000using namespace std;int map[N][N];int dis[N];int main(){ int n; while(cin >> n,n) { for(int i=1; i<N; ++i) for(int e=1; e<N; ++e) map[i][e] = inf; for(int i=1; i<=n; ++i) { int m,a,b; cin >> m; for(int e=1; e<=m; ++e) {cin >> a >>b; map[i][a] = b; } } for(int k=1; k<=n; ++k) for(int i=1; i<=n; ++i) for(int e=1; e<=n; ++e) { if(map[i][k]<inf&&map[k][e]<inf&&map[i][e]>map[i][k]+map[k][e]) map[i][e] = map[i][k]+map[k][e]; } int ma = 10000000,la; memset(dis,0,sizeof(dis)); for(int i=1; i<=n; ++i) for(int e=1; e<=n; ++e) if(i != e) { dis[i] += map[i][e]; } for(int i=1; i<=n; ++i) if(ma > dis[i]) { la = i; ma = dis[i]; } ma = 0; for(int i=1; i<=n; ++i) if(i != la) { if(ma < map[la][i]) ma = map[la][i]; } cout << la <<" "<<ma<<endl; } return 0;}
- poj 1125(最短路)
- POJ 1125(最短路)
- 最短路poj 1125
- poj 1125 最短路
- poj 1125 最短路
- poj 1502 最短路(类似于1125)
- poj 1125 -- Stockbroker Grapevine (最短路)
- POJ 1125 Stockbroker Grapevine (最短路)
- poj 1125 最短路问题
- poj 1125最短路flody
- POJ 1125 最短路 FLOYD
- poj 1125(最短路算法)
- poj 1860(最短路)
- POJ-1860(最短路)
- POJ 3628(最短路)
- POJ 1125 Stockbroker Grapevine(最短路 Floyd)
- POJ 1125Stockbroker Grapevine(floyd最短路)
- POJ 1125 Stockbroker Grapevine(最短路练习)
- 内存访问——直接内存访问(DMA)
- Perl散列(hash)和数组
- 新电脑怎么设置_如何设置电脑
- ios bitmapContext
- Linux内核编译与裁剪(ARM版) .
- POJ 1125(最短路)
- Unix下fork与pthread混用的问题
- 【数据结构】顺序栈、链栈学习笔记
- Grub2配置详解
- 跟随鼠标移动的时钟
- VISTA120报警主机与报警键盘的连接说明
- exit、return、_exit、_Exit这几个函数的区别
- 关于mysql source恢复数据过程中,select操作hang
- Handler机制学习小结