POJ Stockbroker Grapevine(floyd)
https://vjudge.net/problem/POJ-1125
题意:
题意不是很好理解,首先输入一个n,表示有n个股票经纪人,接下来输入n行,每行第一个数m为该股票经纪人认识的经纪人数,然后输入m对数(a,t),表示第i个经纪人把消息传给第a个经纪人所需要的时间。
计算将消息传遍所有人所需要的最少时间。
思路:
起点任意,用floyd比较好。因为floyd求出的是每两点之间的最短路,所以最后计算最小时间时,需要先取最大值,比如说1号经纪人为起点,因为谁都可能为终点,所以枚举所有人,将最大时间作为最小时间,这个应该不难理解。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; const int maxn = + ;
const int INF = 0x3f3f3f3f; int n;
int d[maxn][maxn]; void floyd()
{
for (int k = ; k <= n;k++)
for (int i = ; i <= n;i++)
for (int j = ; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int x, a, t;
while (~scanf("%d", &n) && n)
{
for (int i = ; i <= n; i++)
{
d[i][i] = ;
for (int j = ; j < i; j++)
d[i][j] = d[j][i] = INF;
} for (int i = ; i <= n; i++)
{
scanf("%d", &x);
while (x--)
{
scanf("%d%d", &a, &t);
d[i][a] = t;
}
} floyd();
int stock;
int ans = INF;
for (int i = ; i <= n; i++)
{
int MAX = ;
for (int j = ; j <= n; j++)
{
if (i == j) continue;
MAX = max(MAX, d[i][j]);
}
if (ans > MAX)
{
ans = MAX;
stock = i;
}
}
if (ans == INF)
printf("disjoint\n");
else
printf("%d %d\n", stock, ans);
}
return ;
}
POJ Stockbroker Grapevine(floyd)的更多相关文章
- Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...
- POJ 1125 Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
- POJ 2253 Frogger(floyd)
http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...
- POJ 2240 Arbitrage(floyd)
http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...
- poj 2240 Arbitrage (Floyd)
链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...
- POJ 2253 Frogger (Floyd)
Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissions:57696 Accepted: 18104 Descript ...
- POJ 2431 Expedition(探险)
POJ 2431 Expedition(探险) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] A group of co ...
- POJ 3414 Pots(罐子)
POJ 3414 Pots(罐子) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 You are given two po ...
- POJ 3281 Dining (网络流)
POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...
随机推荐
- log buffer space事件(转)
看了这篇文章: Oracle常见的等待事件说明http://database.ctocio.com.cn/tips/38/6669538.shtml 对于Log Buffer Space-日志缓冲空间 ...
- Java导出Excel表,POI 实现合并单元格以及列自适应宽度(转载)
POI是apache提供的一个读写Excel文档的开源组件,在操作excel时常要合并单元格,合并单元格的方法是: sheet.addMergedRegion(new CellRangeAddress ...
- 遍历DataSet
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Oracle之rman命令的使用全备输出信息的详解(51CTO风哥rman课程)
rman连接数据库 rman target/ catalog rman/rman123456 运行全备命令 backup database; 查看备份集 list backupset;
- kibana 和ES安装配置常见问题解决
1.下载相同版本的kibana和ES: es5.6.5下载地址:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5 ...
- explain 分析 聚合统计语句的性能
EXPLAIN SELECT COUNT(1) FROM question; id select_type table partitions type possible_keys key key_le ...
- Mysql学习笔记—时间计算、年份差、月份差、天数差(转载)
1.获取当前日期 SELECT NOW(),CURDATE(),CURTIME(); 结果类似: 2. 获取前一天 DAY); 当前日期2018-09-17,结果: 3. 获取后一天 DAY); 当前 ...
- 离线安装部署zabbix
一. 安装好CentOS安装过程中添加php,mariadb等所需要的依赖 二. 准备好所有所需的rpm压缩文件包在centos中解压,这里放在根目录下zabbix_rpms文件夹下 三. 安装所需r ...
- mysql8新特性(一)
https://www.oschina.net/news/95325/mysql-8-0-ga-released http://blog.itpub.net/28218939/viewspace-21 ...
- Linux 基础 —— Linux 进程的管理与监控
这篇文章主要讲 Linux 中进程的概念和进程的管理工具.原文:http://liaoph.com/inux-process-management/ 进程的概念 什么是进程 进程(Process)是计 ...