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 ...
随机推荐
- 15分XX秒后订单自动关闭(倒计时)
//订单记录 function get_order(){ //请求订单ajax方法 XX.send_api("method",{data},function(){ var date ...
- 在C#中使用科大讯飞Web API进行语音合成
最近工作中需要用到讯飞语音合成接口,网上看了下基本都是Java,PHP,Python版本的,正好补上C# 版本,代码比较简单. 首先在讯飞开放平台上创建一个WebApi项目,取到APPID与APIK ...
- angular 输出属性
import { Component, OnInit, EventEmitter, Output } from '@angular/core'; @Component({ selector: 'app ...
- 正确处理类的复合关系------新标准c++程序设计
假设要编写一个小区养狗管理程序,该程序需要一个“主人”类,还需要一个“狗”类.狗是有主人的,主人也有狗.假定狗只有一个主人,但一个主人可以有最多10条狗.该如何处理“主人”类和“狗”类的关系呢?下面是 ...
- NSURLSession 网络请求
1.NSURLSession 在 iOS9.0 之后,以前使用的 NSURLConnection 过期,苹果推荐使用 NSURLSession 来替换 NSURLConnection 完成网路请求相关 ...
- 汇编Shellcode的技巧
汇编Shellcode的技巧 来源 https://www.4hou.com/technology/3893.html 本文参考来源于pentest 我们在上一篇提到要要自定义shellcode,不 ...
- 洛谷P2510 [HAOI2008]下落的圆盘(计算几何)
题面 传送门 题解 对于每个圆,我们单独计算它被覆盖的周长是多少 只有相交的情况需要考虑,我们需要知道相交的那段圆弧的角度,发现其中一个交点和两个圆的圆心可以构成一个三角形且三边都已经知道了,那么我们 ...
- request payload
最近在调试代码时发现有Request Payload的情况,从网上查一些文件,也都有较多的描述.下面我只是说明一下大家没有注意的地方 关于HTTP请求,都是通过URL及参数向后台发送数据.主要方式有G ...
- Python3之时间模块time & datetime & calendar
一. 简介 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多python函数用一个元组装起来的9组数字处理时间. python中时间日期格式化符号: %y 两位 ...
- javascript jquery console调试方法说明
控制台(Console)是Firebug的第一个面板,也是最重要的面板,主要作用是显示网页加载过程中产生各类信息. 一.显示信息的命令 Firebug内置一个console对象,提供5种方法,用来显示 ...