POJ 1125 Stockbroker Grapevine(最短路基础题)
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 思路:
先用最短路找一下i-j的最短路径,然后只要找到第i个经纪人的的最长路径也就是最晚接到消息的时间,这就是这个经纪人的耗时,只要比较下所有经济人中耗时最短的就是我们要找的。
至于不连通的这个很容易解决,只要初始化给每条路径一个初始的值(一个很大的数字),floyd之后只要再遍历一遍i经纪人的最长路径,如果他的最长路径是初始值的话,说明有路径
没有连通,直接输出disjoint就好了。这只是数据比较小可以用floyd解决,如果数据比较大的话还好,还是要用其他耗时比较低的算法,比如spfa算法。 实现代码:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 0x3f3f3f3f
#define maxx 9999999
int mp[][],n;
void floyd(){
for(int i = ;i <= n; i++){
for(int j = ;j <= n; j++){
for(int k = ;k <= n; k++){
if(mp[j][k] > mp[j][i]+mp[i][k])
mp[j][k] = mp[j][i] + mp[i][k];
}
}
}
}
int main()
{
int i,j,minn,minx,m,x,y;
while(scanf("%d",&n)&&n){
minn = maxx;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
mp[i][j] = mp[j][i] = maxx;
for(i=;i<=n;i++){
scanf("%d",&m);
while(m--){
scanf("%d%d",&x,&y);
mp[i][x] = y;
}
}
floyd();
for(i=;i<=n;i++){
int ans = ;
for(j=;j<=n;j++){
if(i!=j&&mp[i][j]>ans)
ans = mp[i][j];
}
if(ans<minn){
minn = ans;
minx = i;
}
}
if(minn == maxx) cout<<"disjoint"<<endl;
else cout<<minx<<" "<<minn<<endl;
memset(mp,INF,sizeof(mp));
}
}
POJ 1125 Stockbroker Grapevine(最短路基础题)的更多相关文章
- POJ 1125 Stockbroker Grapevine 最短路 难度:0
http://poj.org/problem?id=1125 #include <iostream> #include <cstring> using namespace st ...
- 最短路(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【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- poj 1125 Stockbroker Grapevine dijkstra算法实现最短路径
点击打开链接 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23760 Ac ...
- 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(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- POJ 1125 Stockbroker Grapevine (Floyd最短路)
Floyd算法计算每对顶点之间的最短路径的问题 题目中隐含了一个条件是一个人能够同一时候将谣言传递给多个人 题目终于的要求是时间最短.那么就要遍历一遍求出每一个点作为源点时,最长的最短路径长是多少,再 ...
随机推荐
- odoo 之报date<form string=''product lc''> 错误
原因是: </page> </notebook> </form> <div class="oe_chatter"> <fiel ...
- 你也可以自己写一个可爱 & 小资风格的Android加载等待自定义View - 转
http://blog.csdn.net/carson_ho/article/details/77712072
- 20155305《网络对抗》PC平台逆向破解(二)
20155305<网络对抗>PC平台逆向破解(二) shellcode注入 1.shellcode shellcode是一段代码,溢出后,执行这段代码能开启系统shell. 2.构造方法 ...
- 20155316 Exp1 PC平台逆向破解(5)M
前绪 实验收获与感想 初步从三个途径了解了什么是缓冲区溢出以及如何简单实现它,对汇编与反汇编有更直观的了解. 什么是漏洞?漏洞有什么危害? 漏洞是指机器体制设计时所没有顾及到的.可以被利用的bug,放 ...
- 从零开始学cookie(个人笔记)——一
未完待续 参考链接 : cookie (储存在用户本地终端上的数据) 关键词: cookie session HTTP 小文本文件 解释 Cookie 是由 Web 服务器保存在用户浏览器上的小文本文 ...
- 20155333 《网络对抗》Exp4 恶意代码分析
20155333 <网络对抗>Exp4 恶意代码分析 基础问题回答 1.如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作有哪 ...
- LSTM生成尼采风格文章
LSTM生成文本 github地址 使用循环神经网络生成序列文本数据.循环神经网络可以用来生成音乐.图像作品.语音.对话系统对话等等. 如何生成序列数据? 深度学习中最常见的方法是训练一个网络模型(R ...
- libgdx学习记录4——舞台Stage
libgdx总的来说是一个框架,而不是一个成熟的游戏引擎.Stage是其中一个比较好的封装,里面自带Camera.SpriteBatch等常用渲染绘图工具. 下面是一个简单的添加图片,并让镜头左右上下 ...
- [BZOJ4144][AMPPZ2014]Petrol[多源最短路+MST]
题意 题目链接 分析 假设在 \(a \rightarrow b\) 的最短路径中出现了一个点 \(x\) 满足到 \(x\) 最近的点是 \(c\) ,那么我们完全可以从 \(a\) 直接走到 \( ...
- vue JointJS 实例demo
前言 越来越发现,前端深入好难哦!虐成渣渣了. 需求:前端绘制灵活的关系图(此demo还是简单的,我的需求才跨出一小步) 安装 npm install jointjs 容器,工具栏 <templ ...