poj 1125 Stockbroker Grapevine(最短路径)
Description
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
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
描述:众所周知,证券业依靠的是过度的传言。你需要想出让股票经纪人传播假消息让雇主在股票市场上的占据优势的方法。为了获得最大的效果,你必须以最快的方式传播谣言。对于你来说不幸的是,股票经纪人只信任来自他们的“可信任的来源”的信息,这意味着你要考虑到他们的接触结构时的谣言。这需要一个特定的经纪人和一定的时间吧谣言传递到每个同事。你的任务是编写一个程序,告诉你选择哪一个股票经纪人为谣言的出发点,以及花费多少时间,谣言才可以传遍了整个股票经纪人社区。这个时间是根据最后一个人得到的信息的时间所衡量的。
输入:你的程序将包含多组股票经纪人的输入数据。每组始于一个股票经纪人的数量。每行的几组数字第一个表示股票经纪人所接触的人以及把消息传递给这个人所花费的时间。每个股票经纪人的格式如下:每行的开始n表示有几对整数,一对为一个传播人。每一对上的第一个数字指的传播人(例如,一个' 1 '的意思是人在该组中的一个),然后是花费几分钟把消息传递给那个人。没有特殊标点符号或间隔规则。
输出:对于每一组数据,你的程序必须输出一行包含的最快的消息传输人结果,以及最后一个人收到消息所花费的所有时间,分钟以整数计时。你的程序可能会收到的一些关系会排除一些人,也就是有些人可能无法访问。如果你的程序检测到这样一个破碎的网络,只需输出消息“disjoint”。请注意,所花费的时间是从A传递消息到B,B传递信息到A不一定是花费同样的传递时间,但此类传播也是可能的。
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define INF 20
#define MAX 150
int path[MAX][MAX];
int t,n;
void Floyd()
{
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i!=j&&path[i][j]>path[i][k]+path[k][j])
path[i][j]=path[i][k]+path[k][j];
}
}
}
int max_len,Min=INF,k=;
for(int i=; i<=n; i++)
{
max_len=;
for(int j=; j<=n; j++)
{
if(i!=j&&path[i][j]>max_len)
max_len=path[i][j];
}
if(max_len<Min)
{
Min=max_len;
k=i;
}
}
if(Min<INF)
cout<<k<<' '<<Min<<endl;
else
printf("disjoint\n");
return ;
}
int main()
{
while(cin>>n,n)
{
memset(path,INF,sizeof(path));
for(int i=; i<=n; i++)
{
scanf("%d",&t);
int a,b;
while(t--)
{
cin>>a>>b;
path[i][a]=b;
}
}
Floyd();
}
return ;
}
poj 1125 Stockbroker Grapevine(最短路径)的更多相关文章
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- 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【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
- poj 1125 Stockbroker Grapevine(多源最短)
id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- POJ 1125 Stockbroker Grapevine(floyd)
http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- Bootstrap(7) 输入框和导航组件
一.输入框组件 文本输入框就是可以在<input>元素前后加上文字或按钮,可以实现对表单控件的扩展. //在左侧添加文字 <!-- //在左侧添加文字 --> ...
- 通过docker-compose构建ghost博客(二)
上一篇通过yml文件构建 ghost博客,这次通过构建nginx服务,并添加反向代理来运行搭建的ghost博客. 目录结构 ghost.conf 就是 定义的nginx 加载的配置文件 server ...
- 微信小程序 错误记录
1.报错this.getUserInfo(this.setData) is not a function;at pages/index/index onShow function;at api req ...
- ios NSUserDefaults存储数据(偏好设置)
ios NSUserDefaults存储数据(偏好设置) 1.NSUserDefaults用于存储数据量小的数据,主要是用户配置,但也可以支持存储一些小数据包括:NSString, NSNumber, ...
- MSDos
一.简介 二.源码 http://www.computerhistory.org/atchm/microsoft-research-license-agreement-msdos-v1-1-v2- ...
- Task 和 ThreadPool
在C#中 TASK 和 ThreadPool 都可以完成多任务并行的工作.但是 TASK实际上是微软定义好的,基于 ThreadPool 的一个类.这里面微软做了很多优化工作. Task Parall ...
- oracle 使用exp命令 sys用户登录 导出表存为dmp文件
在cmd下面,使用exp命令,格式为 exp \"sys/123456@dbname as sysdba\" file=d:\dmp\test.dmp tables=sys.tes ...
- hdu 5493 (2015合肥网赛) Queue
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意,t组数据,n个人,n行每行分别是人的身高和这个人的左边或右边比他高的人的个数,输出符合条件 ...
- java性能优化之for循环
完成同样的功能,用不同的代码来实现,性能上可能会有比较大的差别,所以对于一些性能敏感的模块来说,对代码进行一定的优化还是很有必要的.今天就来说一下java代码优化的事情,今天主要聊一下对于for(wh ...
- Python之线程与进程
今天我们来了解一下Python的线程和进程的管理机制 首先,我们要了解下线程跟进程的概念: 线程(Thread)是操作系统能够进行运算调度的最小的单位,是一堆cpu的指令.他被包含在进程中,是进程中的 ...