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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
随机推荐
- leetcode第一刷_Sudoku Solver
这道题简直是耻辱啊.竟然被吓得不敢做,最终開始写还犯下了各种低级错误,花了好久的时间. 事实上假设想明确81*9事实上是非常小的规模的话,早就想到用回溯法了,这不是跟八皇后全然一样的嘛.每次填入的时候 ...
- 安卓File类汇总
File类 构造函数 參数 File(File dir,String name) File制定构造的新的File对象的路径.而String制定新的File名字 File(String path) St ...
- ubuntu挂载3T新硬盘并更换home分区
ubuntu添加一块新的硬盘,并更换home分区 1.将硬盘接入机箱,开机,查看是否现有的硬盘信息 从这里可以看出,共有两块硬盘,分别是sda和sdb 2.执行fdisk -l,确保我们要添加的就是s ...
- sql server 常用函数 及 方法
返回受上一语句影响的行数: @@ROWCOUNT 语法@@ROWCOUNT 返回类型integer 注释任何不返回行的语句将这一变量设置为 0 ,如 IF 语句. 示例下面的示例执行 UPDATE 语 ...
- 【LeetCode OJ 016】3Sum Closest
题目链接:https://leetcode.com/problems/3sum-closest/ 题目:Given an array S of n integers, find three integ ...
- Jenkins安装和配置系列
转自:http://www.cnblogs.com/zz0412/tag/jenkins/default.html?page=1 Jenkins进阶系列之——18Jenkins语言本地化 Jen ...
- 彻底解决maven Cannot change version of project facet Dynamic Web Module to 3.0?
这个问题是由于maven默认的jdk和默认的Dynamic Web Module版本问题引起的. 这个问题断断续续解决了复发了,今天找打了一个方法 第一,首先要在maven中配置这个插件 <pl ...
- error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决编译php扩展xsl时出现 error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution ...
- 密码学hash函数-SHA256-512
[latexpage] Hash函数又称哈希函数.散列函数.杂凑函数.它是一种单向密码体制,即从一个从明文到密文的不可逆映射,只有加密过程,没有解密过程. Hash函数H将可变长度的数据块M作为输入, ...
- 24模拟keepalved vrrp功能,监听主节点,如果主节点不可访问则备节点启动并配置LVS实现接管主节点的资源提供服务(提醒:注意ARP缓存)
[root@lb04 scripts]# cat ha_lv.sh #!/bin/bash while true do check_count=$(nmap 10.0.0.13|grep " ...