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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- 将之前的Power idea公司的数据按照下图所示的格式在屏幕上显示出来。
之前的文章 示例代码如下 assume cs:codesg ;将整个data段看作是一个数组,长度一共为 ;21*4+21*4+2*21=168+42=210字节 data segment db ' ...
- RecyclerView的点击事件添加-------接口回调的形式添加
package com.example.recyclerviewdemo; import android.support.v7.widget.RecyclerView; import android. ...
- centos7 二进制版本安装 mysql8.0.13
一.下载mysql二进制安装包 mysql官网: https://dev.mysql.com/downloads/mysql/ 由于国内网络问题,个人建议使用国内开源镜像站下载: http://mir ...
- 2.git使用之git fetch和git push的区别
. git fetch:相当于是从远程获取最新版本到本地,不会自动merge git fetch origin master git log -p master..origin/master git ...
- tkinter模块
Python GUI编程(Tkinter) Python 提供了多个图形开发界面的库,几个常用 Python GUI 库如下: Tkinter: Tkinter 模块(Tk 接口)是 Python 的 ...
- 网页 PHP 动态师范
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Numpy 索引
1.一维索引 >>> import numpy as np >>> A = np.arange(3,15) >>> print(A[3]) 6 & ...
- Executors提供的四种线程池
Java 5+中的Executor接口定义一个执行线程的工具.它的子类型即线程池接口是ExecutorService.要配置一个线程池是比较复杂的,尤其是对于线程池的原理不是很清楚的情况下,因此在工具 ...
- DataStructure.BloomFilter
Bloom Filters Ref[1] 1. 简介 Bloom filter(布隆过滤器:有更好的或正确的翻译,告诉我) 是一个数据结构,该数据结构快速并且内存高效,它可以告诉你某个元素是否在集合中 ...
- Business.Startup.Learning from Startup Mistakes at SpringSource
http://www.infoq.com/news/2014/07/startup-spring