POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23440 | Accepted: 12854 |
Description
in the fastest possible way.
Unfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass
the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community.
This duration is measured as the time needed for the last person to receive the information.
Input
and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring
to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.
Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of
stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.
Output
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the
message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.
Sample Input
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0
Sample Output
3 2
3 10
Source
题意:
每个人只可以和他们的朋友们散播谣言
第一行给你 N 个人 【人的编号 1...N】
剩下 N 行
每一行第一个数num代表这个人有多少个朋友,
剩下 num 对数分别代表朋友的编号, 和传消息到这个朋友那儿去的时间
输出能最快传播谣言的人的编号和时间
算法:floyd简单应用
思路:
code:
/**********************************************************************
Accepted 124K 0MS C++ 1362B
题意:问怎么散播谣言最快
每个人只可以和他们的朋友们散播谣言
第一行给你 N 个人 【人的编号 1...N】
剩下 N 行
每一行第一个数num代表这个人有多少个朋友,
剩下 num 对数分别代表朋友的编号, 和传消息到这个朋友那儿去的时间
输出能最快传播谣言的人的编号和时间
算法:floyd简单应用
思路:直接套用floyd后,看哪个人传播谣言的最远距离是最小的就好了
*************************************************************************/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int maxn = 110;
const int INF = maxn*10; int w[maxn][maxn];
int n; void floyd()
{
for(int k = 1; k <= n; k++)
for(int i = 1; i <= n; i++)
for(int j = 1; j <= n; j++)
w[i][j] = min(w[i][j], w[i][k]+w[k][j]);
} int main()
{
while(scanf("%d", &n) != EOF)
{
if(n == 0) break; for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= n; j++)
w[i][j] = (i == j ? 0 : INF);
} int num;
for(int i = 1; i <= n; i++)
{
scanf("%d", &num);
int v,t;
while(num--)
{
scanf("%d%d", &v,&t);
w[i][v] = min(w[i][v], t);
}
} floyd();
int Min = INF;
int index = 1;
for(int i = 1; i <= n; i++)
{
int Max = 0;
for(int j = 1; j <= n; j++)
{
Max = max(Max, w[i][j]);
} if(Max < Min)
{
Min = Max;
index = i;
}
}
if(Min == INF) printf("disjoint\n");
else printf("%d %d\n", index, Min); }
return 0;
}
POJ 1125 Stockbroker Grapevine【floyd简单应用】的更多相关文章
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- POJ 1125 Stockbroker Grapevine (Floyd最短路)
Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- OpenJudge/Poj 1125 Stockbroker Grapevine
1.链接地址: http://poj.org/problem?id=1125 http://bailian.openjudge.cn/practice/1125 2.题目: Stockbroker G ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- POJ 1125 Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- Odoo8中“更多”下拉菜单选项指定后台执行代码
在Odoo8中的仓库模块,根据每日最小安全库存数量,系统会自动生成一些补货单,而且是一个产品会生成一笔,如果产品比较多,这里生成的补货单也会很多. 如果这里的补货单没有即时处理,那相同产品后续不会再生 ...
- 监控应用服务器使用JMX监控Tomcat (推荐)
前言:做了一个监控应用服务器的项目(支持Tocmat.WebSphere.WebLogic各版本), 过程也算是磕磕绊绊,由于网上缺少相关资料,或者深陷于知识的海洋难以寻觅到有效的资料,因而走过不少弯 ...
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- Android 关于ZXing的使用
1.http://blog.csdn.net/ryantang03/article/details/7831826 2.http://blog.csdn.net/xiaanming/article/d ...
- sql server 常用函数 及 方法
返回受上一语句影响的行数: @@ROWCOUNT 语法@@ROWCOUNT 返回类型integer 注释任何不返回行的语句将这一变量设置为 0 ,如 IF 语句. 示例下面的示例执行 UPDATE 语 ...
- ping的原理以及ICMP
ping 的原理: ping 程序是用来探测主机到主机之间是否可通信,如果不能ping到某台主机,表明不能和这台主机建立连接. ping 使用的是ICMP协议,它发送icmp回送请求消 ...
- 用brew安装gcc48
由于mac自带的gcc的版本过低,因此想自己装一个新的gcc. 在网上搜索了一圈后发现用brew install安装比较简单,但可能由于本地的brew有冲突,因此网上的攻略都没有效果. 通过在gith ...
- js中级四: 跨域
原文链接:http://www.cnblogs.com/scottckt/archive/2011/11/12/2246531.html 什么是跨域? 首先什么是跨域,简单地理解就是因为JavaScr ...
- BZOJ 1798 AHOI2009 Seq 维护序列 线段树
题目大意:维护一个序列,提供三种操作: 1.将区间中每个点的权值乘上一个数 2.将区间中每个点的权值加上一个数 3.求一段区间的和对p取模的值 2631的超^n级弱化版.写2631之前能够拿这个练练手 ...
- UVA 12169 Disgruntled Judge 扩展欧几里得
/** 题目:UVA 12169 Disgruntled Judge 链接:https://vjudge.net/problem/UVA-12169 题意:原题 思路: a,b范围都在10000以内. ...