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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- 【Java】Java_16 控制循环结构Break、Continue、Return
1.break break用于完全结束一个循环,跳出循环体.不管是哪种循环,一旦在循环体中遇到break,系统将完全结束该循环 在Java中是的标签定义,标签就是一个紧跟着英文冒号(:)的标识符 代码 ...
- C语言-gdb调试工具详解
回车 重复上一次命令 产生可调试的可执行文件:gcc -g main.c -o main, 必须加上-g选线, 表示在可执行文件中加入源文件信息, 但并不是将源文件嵌入可执行文件, 所以在调试时必须保 ...
- 《C#程序设计教程 -李春保》阅读笔记
<C#程序设计教程 -李春保>阅读笔记 ( 需注意程度:红>粗体>下划线,蓝色:我的疑问 ) 老师的引言 [师]对待一种新语言的关注点 数据类型定义(python不用定 ...
- Linux如何关机与关机命令祥解
Linux关机命令祥解 1.直接关电源 2.init 0 3.telinit 0 4.shutdown -h now 5.halt6.poweroff 1.shutdown shutdown命令安全地 ...
- unity, inspector debug
以前经常因为脚本中private变量不在inspector界面中显示,不方便观察其值的变化,所以本该用private的用了public. 今天发现,原来inspector有个选项,如图,平常勾选的是N ...
- Effective C++ 条款47
本节条款的题目:请使用trait classes来表示类型信息 本节条款主要讲述的技术是怎样在编译期间实现对迭代器类型的推断,依据推断的类型进行最优处理. 我们先来看一下迭代器的种类: 1.input ...
- MapReduce-MulitipleOutputs实现自己定义输出到多个文件夹
输入源数据例子: Source1-0001 Source2-0002 Source1-0003 Source2-0004 Source1-0005 Source2-0006 Source3-0007 ...
- nginx的luajit安装luarocks并安装luafilesystem
nginx的luajit安装luarocks并安装luafilesystem by admin on -- :: in , 69次 标题有点绕口.我尽量把关键词都贴进去.之前因为自己的nginx安装了 ...
- 微信小程序下拉按钮动画
有些时候要求下拉按钮需要动画效果,但又不需要引入插件. 这时需要手动写一个动画. 主要思路: 动态切换class 默认与动画转向的样式编写 上图是默认给出的按钮向下的样式, 上图是动画转向后的样式 上 ...
- Chrome插件之一键保存网页为PDF1.1发布
最新版本:V1.1 下载地址:http://download.csdn.net/detail/bdstjk/5722317 http://pan.baidu.com/share/link?sharei ...