https://vjudge.net/problem/POJ-1125

题意:

题意不是很好理解,首先输入一个n,表示有n个股票经纪人,接下来输入n行,每行第一个数m为该股票经纪人认识的经纪人数,然后输入m对数(a,t),表示第i个经纪人把消息传给第a个经纪人所需要的时间。

计算将消息传遍所有人所需要的最少时间。

思路:

起点任意,用floyd比较好。因为floyd求出的是每两点之间的最短路,所以最后计算最小时间时,需要先取最大值,比如说1号经纪人为起点,因为谁都可能为终点,所以枚举所有人,将最大时间作为最小时间,这个应该不难理解。

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<string>
  4. #include<cstring>
  5. using namespace std;
  6.  
  7. const int maxn = + ;
  8. const int INF = 0x3f3f3f3f;
  9.  
  10. int n;
  11. int d[maxn][maxn];
  12.  
  13. void floyd()
  14. {
  15. for (int k = ; k <= n;k++)
  16. for (int i = ; i <= n;i++)
  17. for (int j = ; j <= n; j++)
  18. d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  19. }
  20.  
  21. int main()
  22. {
  23. //freopen("D:\\txt.txt", "r", stdin);
  24. int x, a, t;
  25. while (~scanf("%d", &n) && n)
  26. {
  27. for (int i = ; i <= n; i++)
  28. {
  29. d[i][i] = ;
  30. for (int j = ; j < i; j++)
  31. d[i][j] = d[j][i] = INF;
  32. }
  33.  
  34. for (int i = ; i <= n; i++)
  35. {
  36. scanf("%d", &x);
  37. while (x--)
  38. {
  39. scanf("%d%d", &a, &t);
  40. d[i][a] = t;
  41. }
  42. }
  43.  
  44. floyd();
  45. int stock;
  46. int ans = INF;
  47. for (int i = ; i <= n; i++)
  48. {
  49. int MAX = ;
  50. for (int j = ; j <= n; j++)
  51. {
  52. if (i == j) continue;
  53. MAX = max(MAX, d[i][j]);
  54. }
  55. if (ans > MAX)
  56. {
  57. ans = MAX;
  58. stock = i;
  59. }
  60. }
  61. if (ans == INF)
  62. printf("disjoint\n");
  63. else
  64. printf("%d %d\n", stock, ans);
  65. }
  66. return ;
  67. }

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. Thinkphp --- 入口文件

    通常入口文件是 index.php <?php define('APP_DEBUG',true); //define('BIND_MODULE','Home'); 这句代码会自动生成Home模块 ...

  2. Windows系统下做定时任务为Oracle数据库每天自动备份

    1.创建备份目录d:\backup, 创建批处理命令Bak.bat,编写备份脚本 ? 1 2 exp user/passwd@orcl DIRECT=Y BUFFER=100000 FILE=D:\b ...

  3. PL/SQL编程基础(一):PL/SQL语法简介(匿名PL/SQL块)

    PL/SQL PL/SQL是Oracle在关系数据库结构化查询语言SQL基础上扩展得到的一种过程化查询语言. SQL与编程语言之间的不同在于,SQL没有变量,SQL没有流程控制(分支,循环).而PL/ ...

  4. 为什么 要弄清楚 mysql int(5) int(11) bigint 自建mysql主键id python random 科学计数法

    场景: 有1.2亿条问答数据,相同问题的不同答案为不同条的数据,且该表数据逐日递增: 第三方需求(不合理): 将问题.答案数据分别放入问题表.答案表: 问题表的主键为整数,在答案表中,每行数据有相应的 ...

  5. HTTP监视器charles入门使用教程分享---http/s packet monitors---ubuntu installation

    charles --usage http://www.cnblogs.com/chenlogin/p/5849471.html 按照Charles的提示,PC打开 chls.pro/ssl下载得到一个 ...

  6. 崩溃block

    [__NSGlobalBlock__ setHidden:]: unrecognized selector sent to instance 0x10dbb9090(null)注释掉 sethidde ...

  7. pickle库的使用

    http://www.php.cn/python-tutorials-372984.html

  8. cocos2d 特效

    一.特效概念 特效是让精灵(CCSprite)执行某种特殊的效果.其实,特效也是一种动画! 但是,为什么要把特效与动画区分呢?因为,特效是基于网格属性来进行的. 如何区分动画与特效?简单的将,当使用到 ...

  9. innobackupex 还原和备份实例

    InnoDB 和非 InnoDB 文件的备份都是通过拷贝文件来做的,但是实现的方式不同,前者是以page为粒度做的(xtrabackup),后者是 cp 或者 tar 命令(innobackupex) ...

  10. 205-react SyntheticEvent 事件

    参看地址:https://reactjs.org/docs/events.html