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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- HTML5中音频视频标签使用
HTML5中音频视频标签使用的最好方式 Html5中提供了<audio> <vedio>元素实现音频视频的引入播放 然而更好的方式
- A.0 B.1 C.2 D.3
17. 以下哪个不是广告平台? A.Admob B.Domob C.InMobi D.TalkingData 错误 应该选择:D.TalkingData 10. 哪个不是免费的工具? A.Xcode ...
- Linux下使用Fastboot给手机刷ROM
前言 一直在刷机.失败.刷机.失败中,还好今天有个任务能够使用fastboot刷机.好开心,最终不用切换系统了.(话说好久没有写代码了,身为一个互联网程序猿,不写代码我easy紧张). 开发环境 Ub ...
- NodeJS on Nginx: 使用nginx反向代理处理静态页面
最近OurJS后台已经从纯node.js迁移到了Nginx+NodeJS上来了,感觉性能提升了不少,特与大家分享. Nginx ("engine x") 是一个高性能的 HTTP ...
- Python MySQLdb 使用utf-8 编码插入中文数据
参考地址:http://blog.csdn.net/dkman803/article/details/1925326/ 本人在使用python,mysqldb操作数据库的时候,发现如下问题,编码如下: ...
- 嵌入式实时操作系统Nucleus PLUS综述
近些年来,随着嵌入式系统飞速的发展.嵌入式实时操作系统广泛地应用在制造工业.过程控制.通讯.仪器仪表.汽车.船舶.航空航天.军事.装备.消费类产 品等方面. Nucleus PLUS 是为实时嵌入式应 ...
- php对象序列化和cookie的问题,反序列化false
php对象序列化和cookie的问题,反序列化false $searchKeywords = array("羊奶","肥皂"); $searchKeywords ...
- 一篇关于arc下内存管理的老文章,包含各种冷门修饰符(关于内存),写的较好,mark
http://blog.csdn.net/zhibudefeng/article/details/7746201
- 转:NHibernate 存储过程
http://stackoverflow.com/questions/928847/how-to-get-the-return-value-from-a-sql-server-stored-proce ...
- printf不支持%lf
#include <stdio.h> int square137(int n); void p137() { double x = 3.0; int y = (int)x; printf( ...