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)的更多相关文章

  1. Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...

  2. POJ 1125 Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...

  3. POJ 2253 Frogger(floyd)

    http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...

  4. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  5. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  6. POJ 2253 Frogger (Floyd)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:57696   Accepted: 18104 Descript ...

  7. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  8. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

  9. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

随机推荐

  1. 使用Martix来实现缩放图片的功能

    使用Martix(android.graphics.Matrix)类中的postScale()方法结合Bitmap来实现缩放图片的功能 Bitmap bmp = BitmapFactory.decod ...

  2. 几何+点与线段的位置关系+二分(POJ2318)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10666   Accepted: 5128 Description ...

  3. 310实验室 Linux 软件安装常见问题

    电脑装好Linux系统后,系统默认安装软件不齐,需要自己根据自己的需要安装一些列工具软件,在linux系统中,用的最多的就是Synaptic Package Manager,什么是Synaptic?新 ...

  4. 170801、VM性能调优

    最近因项目存在内存泄漏,故进行大规模的JVM性能调优 , 现把经验做一记录. 一.JVM内存模型及垃圾收集算法 1.根据Java虚拟机规范,JVM将内存划分为: New(年轻代) Tenured(年老 ...

  5. SaltStack配置管理-状态间关系

    上一篇:SaltStack配置管理-LAMP状态设计 include包含 上篇安装LAMP环境是一个个环境安装,可以通过include模块全部安装 lamp.sls include: - apache ...

  6. With all Java versions it is strongly recommended to not use experimental -XX JVM options.

    https://lucene.apache.org/solr/7_6_0//SYSTEM_REQUIREMENTS.html System Requirements Apache Solr runs ...

  7. 转!!CMPP 网关错误码说明

    http://www.163duanxin.com/msg/1753.htm CMPP错误码说明   与中国移动代码的对应关系. MI::zzzzSMSC返回状态报告的状态值为EXPIREDMJ:zz ...

  8. centos 配置redis

    一.配置redis 简介:Redis是使用c语言开发的一个高性能键值数据库.Redis可以通过一些键值类型来存储数据. 下载:官网地址:http://redis.io/ 下载地址:http://dow ...

  9. centos vim编辑器 第八节课

    centos  vim编辑器  第八节课 其他编辑器: nanogeditemacs 腾讯云上的vim版本~ VIM - Vi IMproved ~ ~ version 7.4.629 ~ by Br ...

  10. 基于 Spark 的文本情感分析

    转载自:https://www.ibm.com/developerworks/cn/cognitive/library/cc-1606-spark-seniment-analysis/index.ht ...