OpenJudge/Poj 1125 Stockbroker Grapevine
1.链接地址:
http://poj.org/problem?id=1125
http://bailian.openjudge.cn/practice/1125
2.题目:
Stockbroker Grapevine
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24810 Accepted: 13674 Description
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours 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
Your
program will input data for different sets of stockbrokers. Each set
starts with a line with the number of stockbrokers. Following this is a
line for each stockbroker which contains the number of people who they
have contact with, who these people are, 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
For
each set of data, your program must output a single line containing the
person who results in the fastest message transmission, and how long
before the last person will receive any given message after you give it
to this person, measured in integer minutes.
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
0Sample Output
3 2
3 10Source
3.思路:
4.代码:
#include <iostream>
#include <cstdio> using namespace std;
int dis[][];//最多为100,为了防止溢出订为105
void Floyd(int n)
{
int i,j,k;
for(i=;i<=n;i++)
for(j=;j<=n;j++)
for(k=;k<=n;k++)
//dp,使用弗洛伊德算法
if(dis[j][i]+dis[i][k]<dis[j][k]){
dis[j][k]=dis[j][i]+dis[i][k];
}
}
void Min(int n)
{
int node,min=0xfffff;//0xfffff为最大int数
int i,j;
for(i=;i<=n;i++){
int max=;
for(j=;j<=n;j++){
if(i==j) continue;
//找出个人传到每个人的最大的时间
if(dis[i][j]>max) max=dis[i][j];
}
if(max<min){
//比较每个人的最大时间,寻找最小的一人
min=max;
node=i;
}
}
if(min<0xffff){
printf("%d %d\n",node,min);
}
else{
printf("disjoint\n");
} }
int main()
{
int n,i,j,k,m; //初始化邻接矩阵
while(scanf("%d",&n)&&n){
for(i=;i<=n;i++){
for(j=;j<=n;j++){
dis[i][j]=0xfffff;
}
}
//m为人数
for(i=;i<=n;i++){
scanf("%d",&m); for(j=;j<m;j++){//k为认识的人
scanf("%d",&k);
scanf("%d",&dis[i][k]);
}
}
Floyd(n);
Min(n);
}
return ;
}
OpenJudge/Poj 1125 Stockbroker Grapevine的更多相关文章
- 最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine
题目传送门 /* 最短路:Floyd模板题 主要是两点最短的距离和起始位置 http://blog.csdn.net/y990041769/article/details/37955253 */ #i ...
- 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 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 最短路 难度: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 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...
- poj 1125 Stockbroker Grapevine(最短路 简单 floyd)
题目:http://poj.org/problem?id=1125 题意:给出一个社交网络,每个人有几个别人可以传播谣言,传播谣言需要时间.问要使得谣言传播的最快,应该从那个人开始传播谣言以及使得所有 ...
- Poj 1125 Stockbroker Grapevine(Floyd算法求结点对的最短路径问题)
一.Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a ...
随机推荐
- 制作第三方SDK静态库、.framework
静态库和动态库的存在形式 静态库: .a 和 .framework 动态库: .dylib 和 .framework 静态库和动态库的使用区别: 静态库:链接时,静态库会被完整地复制 到 可执行文件中 ...
- APP上架详细流程-2016最新
注:文章为博主原创,转载请注明出处 由于新项目要上架,并且发现了与以往不同的地方特此总结 原料: 0.MAC一台 1.可用的开发者账号 2.AppID 3.发布证书 4.描述性文件 上架步骤: 一.在 ...
- iOS 正则表达式小结
#pragma mark - 正则第一种表示方式-利用NSPredicate(谓词)匹配// NSString *email = @"15078357696@163.com" ...
- Android大图片裁剪终极解决方案 原理分析
约几个月前,我正为公司的APP在Android手机上实现拍照截图而烦恼不已. 上网搜索,确实有不少的例子,大多都是抄来抄去,而且水平多半处于demo的样子,可以用来讲解知识点,但是一碰到实际项目,就漏 ...
- Eclipse+Maven构建web项目及部署时Maven lib依赖问题的解决
目录 Eclipse中m2e插件构建web项目的步骤 Maven工具构建web项目再导入Eclipse的步骤 [一].Eclipse中m2e插件构建web项目的步骤 第一步:创建项目,按照 New – ...
- UITextView光标在中间的问题
if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) { self.automatica ...
- SVN 中trunk、branches、tags都什么意思?
1.trunk是主分支,是日常开发进行的地方. 2.branches是分支.一些阶段性的release版本,这些版本是可以继续进行开发和维护的,则放在branches目录中.又比如为不同用户客制化的版 ...
- Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid
F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Java算法实例集合
这里是princeton搜集的算法课程Java示例.包括超过了100 Java个算法程序源码.Javadoc和测试数据.点击这里查看.
- 上struts2的xml在<result type="redirect">参数问题
今天做项目,我遇到了一个精彩的问题. 我需要在struts的xml中的<action>的<result>中配置type="redirect".同一时候须要传 ...