TOJ 2857 Stockbroker Grapevine
描述
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.
输入
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.
输出
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.
样例输入
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
样例输出
3 2
3 10
题目来源
求一个Stockbroker把消息传递给其他Stockbroker所用的最短时间。
floyd求出两点之间消息传递的时间后,再求最短时间。
#include <stdio.h>
#define MAXN 105
#define inf 0x3f3f3f3f int N;
int map[MAXN][MAXN];
int ans[MAXN]; void floyd(){
for(int k=; k<=N; k++){
for(int i=; i<=N; i++){
for(int j=; j<=N; j++){
if(i==k||i==j)continue;
if(map[i][k]!=inf && map[k][j]!=inf &&
map[i][k]+map[k][j]<map[i][j]){
map[i][j]=map[i][k]+map[k][j];
}
}
}
}
}
int main(int argc, char *argv[])
{
int t,u,v,w;
while(scanf("%d",&N)!=EOF && N){
for(int i=; i<=N; i++){
for(int j=; j<=N; j++){
if(i==j)map[i][j]=;
else map[i][j]=inf;
}
}
for(int u=; u<=N; u++){
scanf("%d",&t);
while(t--){
scanf("%d %d",&v,&w);
map[u][v]=w;
}
ans[u]=-;
}
floyd();
for(int i=; i<=N; i++){
for(int j=; j<=N; j++){
if(map[i][j]>ans[i])ans[i]=map[i][j];
}
}
int min=inf,index;
for(int i=; i<=N; i++){
if(ans[i]<min){
min=ans[i];
index=i;
}
}
if(min==inf){
printf("disjoint\n");
}else{
printf("%d %d\n",index,min);
}
}
return ;
}
TOJ 2857 Stockbroker Grapevine的更多相关文章
- Stockbroker Grapevine(floyd+暴力枚举)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31264 Accepted: 171 ...
- 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 ...
- 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
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
- POJ 1125 Stockbroker Grapevine【floyd简单应用】
链接: http://poj.org/problem?id=1125 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
- Stockbroker Grapevine(最短路)
poj——1125 Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 36112 ...
随机推荐
- Sql Server - CURSOR (游标)
1.声明游标 DECLARE 游标名 CURSOR SELECT语句(注:此处一定是SELECT语句) 2.打开游标 OPEN 游标名 3.读取 ...
- JQuery中一些常用函数的运用
一.JQuery的效果介绍 二.定时弹出广告图片JQ部分代码 <script type="text/javascript"> var time; $(function( ...
- Listview 利用Datapager进行分页
原文:http://lgm9128.blog.163.com/blog/static/421734292010513111851101/ <asp:ListView ID="ListV ...
- 创建Database Diagrams时遇到的问题
SQL2008 R2中时,Diagrams的问题 Error: ------------------------------ Database diagram support objects cann ...
- 十五、Node.js-fs模块(中)
有了上一篇JS同步异步知识的铺垫,我们一起学习一下fs模块的同步和异步知识: Node.js内置的fs模块就是文件系统模块,负责读写文件. 和所有其它JavaScript模块不同的是,fs模块同时提供 ...
- Mybatis中的连接池
Mybatis中DataSource的存取 MyBatis是通过工厂模式来创建数据源DataSource对象的,MyBatis定义了抽象的工厂接口:org.apache.ibatis.datasour ...
- windows server2008虚拟机系统盘扩容
windows server2008虚拟机的系统盘空间过小,对系统盘进行扩容,操作如下: 1.将虚拟机关机: 2.VMware对该虚拟机进行设置,选中磁盘,点击扩容,输入扩容大小,等待扩容完成: 3. ...
- 【转】远程桌面关闭后TeamViewer不能连接
源地址:http://www.cnblogs.com/qk2014/p/9274852.html 1.本地安装TeamViewer,完成后如下: 2.远程服务器也安装TeamViewer 在本地Tea ...
- 泛型1(一些algorithm函数)
泛型算法本身不会执行容器的操作,它们只会运行于迭代器之上,执行迭代器的操作.因此算法可能改变容器中保存的元素,也可能在容器内移动元素,但永远不会直接添加或删除元素. 只读算法: accumulate: ...
- I/O(输入/输出)---File类
File:表示文件与目录.用它来对文件或目录进行基本操作,它可以查出文件的基本相关信息,比如:名称.最后的修改日期.文件大小. 使用File类操作文件和目录属性步骤: 1.引入File类 import ...