POJ1125 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
Source
正解:floyd算法
解题报告:
实实在在的水题,给定一个有向图,求一个源点使得到所有点的距离的最大值最小。
数据范围小,直接跑floyd,水过。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = ;
const int inf = ;
int a[MAXN][MAXN];
int n; int main()
{
while() {
scanf("%d",&n);
if(n==) break;
int x,y,z; for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
a[i][j]=inf; for(int i=;i<=n;i++) {
scanf("%d",&x);
if(!x) continue;
for(int j=;j<=x;j++) scanf("%d%d",&y,&z),a[i][y]=z;
} for(int k=;k<=n;k++)
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
if(i!=j && j!=k)
a[i][j]=min(a[i][j],a[i][k]+a[k][j]); int ans=inf,jilu=-; bool flag=false;
for(int i=;i<=n;i++)
{
int now=;
for(int j=;j<=n;j++)
if(i==j) continue;
//else if(a[i][j]>=inf) { printf("disjoint\n"); flag=true; break; }
else now=max(now,a[i][j]); if(now<ans) { ans=now; jilu=i; }
} for(int i=;i<=n && !flag;i++) {
int total=;
for(int j=;j<=n;j++) {
if(i!=j && a[j][i]>=inf && i!=jilu) total++;
}
if(total==n-) flag=true;
} if(!flag) printf("%d %d\n",jilu,ans);
else { printf("disjoint\n"); }
}
return ;
}
POJ1125 Stockbroker Grapevine的更多相关文章
- POJ1125 Stockbroker Grapevine(spfa枚举)
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- POJ1125 Stockbroker Grapevine(最短路)
题目链接. 分析: 手感不错,1A. 直接穷举的起点, 求出不同起点到其它点最短路中最长的一条的最小值(好绕). #include <iostream> #include <cstd ...
- poj1125 Stockbroker Grapevine Floyd
题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...
- POJ1125 Stockbroker Grapevine 多源最短路
题目大意 给定一个图,问从某一个顶点出发,到其它顶点的最短路的最大距离最短的情况下,是从哪个顶点出发?须要多久? (假设有人一直没有联络,输出disjoint) 解题思路 Floyd不解释 代码 #i ...
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
- poj1125&zoj1082Stockbroker Grapevine(Floyd算法)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Description Stockbrokers are known to ...
- POJ 1125 Stockbroker Grapevine
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 33141 Accepted: ...
- Stockbroker Grapevine(floyd)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 28231 Accepted: ...
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
随机推荐
- 【hibernate】<第二节>hibernate的一对多映射(基本类型)
所需工具与前文一致! 第一部分内容:基本类型的一对多(one to many) 以部门表与员工表为例: 目录结构: hibernate.cfg.xml内容 <?xml version=" ...
- java 21 - 9 复制图片的4种方式
需求:复制图片 分析: 因为图片我们用记事本打开后无法读懂,所以用字节流 并且字节流复制有4种方式,所以我们尝试4种方式. 推荐第四种:缓冲字节流一次读取一个字节数组 首先写main方法: publi ...
- f2fs解析(八)node 管理器中的node_info
free_info 功成身退,node_info顺利接班. // 这里还是蛮复杂的一件事,如果不搞清除的话,这个历史性的接班工作我们就接不上 上面说到 alloc_nid 和 alloc_nid_do ...
- poj 1163 The Triangle
The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43809 Accepted: 26430 De ...
- SEO在网页制作中的应用
1.什么是SEOSEO(Search Engine Optimization)中文意译为“搜索引擎优化”.SEO是指通过网站内部调整优化及站外优化,使网站满足搜索引擎收录排名需求,在搜索引擎中提高关键 ...
- [转]CodeSmith和PowerDesigner的使用安装和数据库创建
最近要忙期考,但还是决定每天抽点空来写CodeSmith的系列文章了,在此实在不敢用教程这个词语,毕竟自己对CodeSmith了解的也不是很多,有很多牛人都在博客园发布了不少关于CodeSmith的文 ...
- Jdev Run Page 没有反应
从旧电脑把原有的Jdeveloper完整的拷贝至新电脑,且已完整配置JDEV_USER_HOME,JAVA_HOME等环境变量, Run Page报以下错误. [Starting OC4J using ...
- php基础09:提取表单数据
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 如何“刷leetcode”
做题目的: 获得 offer 巩固算法与数据结构知识,将学到的东西用出来 如何做题: 根据章节与难度来做. 比如你学了 linked list,就去找到标签为 linked list 的题目,然后根据 ...
- 1.1Linux 系统简介(学习过程)
=====课程笔记===== 一.Linux 为何物 Linux 是一个操作系统,就像你多少已经了解的 Windows(xp,7,8)和 Max OS . Linux 也就是系统调用和内核两层,我们使 ...