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 ...
随机推荐
- Thinkphp --- 入口文件
通常入口文件是 index.php <?php define('APP_DEBUG',true); //define('BIND_MODULE','Home'); 这句代码会自动生成Home模块 ...
- Windows系统下做定时任务为Oracle数据库每天自动备份
1.创建备份目录d:\backup, 创建批处理命令Bak.bat,编写备份脚本 ? 1 2 exp user/passwd@orcl DIRECT=Y BUFFER=100000 FILE=D:\b ...
- PL/SQL编程基础(一):PL/SQL语法简介(匿名PL/SQL块)
PL/SQL PL/SQL是Oracle在关系数据库结构化查询语言SQL基础上扩展得到的一种过程化查询语言. SQL与编程语言之间的不同在于,SQL没有变量,SQL没有流程控制(分支,循环).而PL/ ...
- 为什么 要弄清楚 mysql int(5) int(11) bigint 自建mysql主键id python random 科学计数法
场景: 有1.2亿条问答数据,相同问题的不同答案为不同条的数据,且该表数据逐日递增: 第三方需求(不合理): 将问题.答案数据分别放入问题表.答案表: 问题表的主键为整数,在答案表中,每行数据有相应的 ...
- HTTP监视器charles入门使用教程分享---http/s packet monitors---ubuntu installation
charles --usage http://www.cnblogs.com/chenlogin/p/5849471.html 按照Charles的提示,PC打开 chls.pro/ssl下载得到一个 ...
- 崩溃block
[__NSGlobalBlock__ setHidden:]: unrecognized selector sent to instance 0x10dbb9090(null)注释掉 sethidde ...
- pickle库的使用
http://www.php.cn/python-tutorials-372984.html
- cocos2d 特效
一.特效概念 特效是让精灵(CCSprite)执行某种特殊的效果.其实,特效也是一种动画! 但是,为什么要把特效与动画区分呢?因为,特效是基于网格属性来进行的. 如何区分动画与特效?简单的将,当使用到 ...
- innobackupex 还原和备份实例
InnoDB 和非 InnoDB 文件的备份都是通过拷贝文件来做的,但是实现的方式不同,前者是以page为粒度做的(xtrabackup),后者是 cp 或者 tar 命令(innobackupex) ...
- 205-react SyntheticEvent 事件
参看地址:https://reactjs.org/docs/events.html