poj-1125-Stockbroker Grapevine-Floyd

1125:Stockbroker Grapevine (股票经纪人 Grapevine)(已翻译) 1125:Stockbroker Grapevine (股票经纪人 Grapevine)(已翻译) 有AC代码 阅读详情
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
0

Sample Output

3 2
3 10



众所周知,证券经纪业依靠的就是过度的传言。您需要想出股票经纪人中传播假情报的方法,让您的雇主在股票市场的占据优势。为了获得最大的效果,你必须蔓延最快的方式谣言。
不幸的是你,股票经纪人信息只信任他们的“可靠来源”,这意味着你在你传播谣言之前必须考虑到他们的接触结构。它需要特定股票经纪人和一定的时间把谣言传递给他的每一位同事。你的任务将是写一个程序,告诉您选择哪一个股票经纪人作为谣言的出发点和所花费多少时间将谣言扩散到整个社会的股票经纪人。这一期限是衡量过去的人收到信息所需的时间。
输入
你的程序包含多组股票经纪人的输入数据。每组以股票经纪人的人数开始。接下来的几行是每个经纪人与其他人接触的一些信息,包括这些人都是谁,以及将讯息传达到他们所需的时间。每个经纪人与其他人接触信息的格式如下:开头的第一个数表示共有n个联系人,接下来就有n对整数。每对整数列出的第一个数字指的是一个联系人(例如,一个'1'是指编号1的人),其次是在传递一个信息给那个人时所采取分钟的时间。没有特殊的标点符号或空格规则。
每个人的编号为1至经纪人数目。所花费的传递时间是从1到10分钟(含10分种)。股票经纪的人数范围是从1到100。当输入股票经纪人的人数为0时,程序终止。
输出
在对于每一组数据,你的程序必须输出一行,包括的信息有传输速度最快的人,以及在最后一个人收到消息后,所总共使用的时间(整数分钟计算)。
你的程序可能会收到的一些关系会排除一些人,也就是有些人可能无法访问。如果你的程序检测到这样一个破碎的网络,只需输出消息“disjoint”。请注意,所花费的时间是从A传递消息到B,B传递信息到A不一定是花费同样的传递时间,但此类传播也是可能的。

 

 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAX 0x3f3f3f3f
int n;
int map[150][150];
int main()
{
   while(~scanf("%d",&n)&&n)
   {
       int i = 0;
       for(i = 0; i <= n; i++)
        for(int j = 0; j <= n; j++)
            map[i][j] = MAX;
       for(i = 1; i <= n; i++)
       {
           int m,b,s;
           scanf("%d",&m);
           while(m--)
           {
               scanf("%d%d",&b,&s);
               map[i][b] = s;
           }
       }
       for(i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
         for(int k = 1; k <= n; k++)
            if(map[k][i] + map[i][j] < map[k][j]&&j!=k)
                  map[k][j] = map[k][i]+map[i][j];
       int flag ;
       int maxleg;
       int min_in = MAX;
       for(i = 1; i <= n; i++)
       {
           maxleg = 0;
           for(int j = 1; j <= n; j++)
            if(i != j && maxleg < map[i][j])
                maxleg = map[i][j];
           if(min_in >maxleg)
           {
               min_in = maxleg;
               flag = i;
           }

       }
       if(min_in < MAX)
       printf("%d %d\n",flag,min_in);
       else
        printf("disjoint\n");
   }
    return 0;
}


POJ 1125 Stockbroker Grapevine(floyd算法) #include #include #include #include /** * 代码好丑 */ /** * @note 题意: N个股票经纪人,每个股票经纪人都会将得到的消息传播给另外一些股票经纪人,传播的速度均不固定,且从A传到B的速度和B传到A的速度不一定相等。 给定一个消息,并不一定能够传遍所有的股票经纪人,因为股票经纪人可能形成一座座“孤岛”,使得信息无法送达。 现在给定 阅读详情

相关推荐

CCS安装教程图解说明:可视化步骤快速上手

通过清晰的图解步骤详解CCS安装过程,帮助新手快速掌握环境搭建。结合ccs安装教程与实际操作界面,每一步都直观易懂,大幅降低学习门槛,提升配置效率。

weixin_42611310的博客 979

Stockbroker Grapevine (弗洛伊德算法)

Stockbroker Grapevine Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total Submission(s) : 28   Accepted Submission(s) : 16 Problem Description Stockbrokers are

sdau20163940的博客 628

STM32F407控制舵机

STM32F407控制舵机运行 使用STM32F407控制舵机,首先来看下舵机图片 [黑红白,黑线接GND,红线接VCC,信号线接白色线(有的舵机线的颜色不同,例如褐色红色橘色,仅颜色不同接法还如上述)] 舵机需要信号的周期为20ms,即频率为50Hz。 接下来正式操作: 步骤一:STM32F4程序(本次程序的PWM信号产生的周期频率由定时器TIM14通道1产生(TIM14_CH1),想要使用其它定时器也没关系下面会讲到) #include "pwm.h" void TIM14_CH1_PWM_In

Ievn_Hare的博客 1万+

POJ 1125 Stockbroker Grapevine

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

zhengjihao的博客 343

LVGL 实战:虚拟列表与对象复用机制在嵌入式GUI中的性能优化

本文深入探讨LVGL虚拟列表与对象复用机制在嵌入式GUI中的性能优化实践。通过复用机制动态管理UI对象,大幅降低内存占用,实现无限滚动列表的流畅体验。文章详细解析核心算法、内存优化策略及跨平台适配技巧,帮助开发者在资源受限设备上高效处理大量数据展示。

rice5的博客 1107

【QEMU系统分析之TPM篇(一)】

本文以 QEMU 8.2.2 为例,分析其 TPM-emulator 模块的实现,并为 QEMU 添加 Windows 平台的TPM 模拟器的支持。

David唐辉的博客 1196

POJ 刷题系列:1125. Stockbroker Grapevine

POJ 刷题系列:1125. Stockbroker Grapevine传送门:1125. Stockbroker Grapevine题意: 给出一幅有向图,从某个结点s出发,能够抵到其他任何顶点,且传播到最后一个顶点所需要的时间最短,求s。 思路: 数据很水,用floyd求出任意两点之间的最短距离即可。接着遍历顶点s,求出抵达最后一个顶点的时间t,每个s对应一个t,求出t最小的s。代码如下:

Demon-初来驾到 606

Linux之SUSE系统SAP-HANA经常系统内存不足使得SAP应用不能使用解决方案

问题描述 Linux内存使用量超过阈值,使得sap应用程序无可用内存,最终导致程序崩溃。 问题原因 自己查阅了一些资料,也基于zabbix的可用内存和实际不太一样入手去找原因发现问题出现于Cached的值过大,导致系统没有可以再分配的内存空间。Cached只要用来缓存文件的,经常读写的文件会被缓存到Cached中,可以增加读写效率,该功能是Linux系统内核提供的,而SAP-HANA的日志文件很大...

liuxiangyang_的博客 6713

Stockbroker Grapevine (弗洛伊德)

Problem 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 tactica

a1046765624的博客 523

RK3576 Buildroot 双机 ADB 异常排障实录:同版 `boot.img`,一台可识别一台不可识别

进程在跑”不等于“USB 枚举成功”,adbd存活只是必要不充分条件。生产环境中的全局别名可能反向污染系统脚本。shell 命令替换中的字符串问题,必须做字节级验证(od -tx1相比“改环境规避”,核心脚本对输入做鲁棒处理更可长期维护。

小灰灰的博客 221

动态SLAM中的YOLO与ORB-SLAM3融合:实时目标检测与动态点云滤除实战

本文介绍了如何结合YOLOv5目标检测与ORB-SLAM3视觉SLAM系统,实现动态环境下的目标检测与视觉SLAM任务。文章详细阐述了从源码下载、依赖安装(包括libtorch配置)、编译运行步骤(包括ROS环境和非ROS环境下的编译方法),到RGBD-TUM数据集准备与关联处理的全流程。同时针对常见错误提供了解决方案,如libtorch路径配置、ROS环境冲突等。最后展示了系统运行方法,并探讨了未来可能的优化方向,包括增强目标检测能力和改进动态环境下的地图构建。该集成系统为机器人智能导航和环境感知提供了有

LXY_LOVE36的博客 240

POJ 1125 Stockbroker Grapevine //Floyd算法

题目描述POJ1125 Stockbroker Grapevine解题思路找出一个人,使谣言从其传出到所有人用时最短. (1):用Floyd先算出某人到每个人的最短时间,再对时间取最大 (保证每个人都能收到谣言…) = =| (2):对每个人执行(1),取时间最小,即为所求.参考代码#include <iostream> #include <algorithm> #include <cstdio

FZU_zyt的专栏_(:з」∠)_ 381

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

poj 1125 Stockbroker Grapevine(floyd)

http://blog.csdn.net/lyy289065406/article/details/6645856这个题解题目翻译的很棒。题目很简单#include <cstdio> #include <cstring> #define INF 999999 #define MAXN 110int map[MAXN][MAXN]; int n;void floyd() { for(int k

梦幻的蔷薇色 300

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

POJ 1125 Stockbroker Grapevine - (Floyd)

题目链接:http://poj.org/problem?id=1125 #include &lt;stdio.h&gt; #include &lt;algorithm&gt; using namespace std; const int N = 105 + 3; const int MAXN = 10000; int matrix[N][N][N]; //POJ 1125 Stockbroke...

rsy56640的博客 184

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

POJ 1125 Stockbroker Grapevine(Floyd)

POJ 1125 Stockbroker Grapevine(Floyd) http://poj.org/problem?id=1125 题意:给你一个有向图,现在要你找一个起点来传播消息,问你要找那个点传播能使得其他所有点最快时间收到消息.即求到其他所有点的最短距离中的最大值最小的那个点. 分析:        建图,Floyd算法求解.然后一次求出所有点作为源点时的最短距离最大值即可.

code 1056

最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

题目传送门 1 /* 2 最短路:Floyd模板题 3 主要是两点最短的距离和起始位置 4 http://blog.csdn.net/y990041769/article/details/37955253 5 */ 6 #include <cstdio> 7 #include <iostrea...

weixin_30558305的博客 81

POJ 1125 floyd算法 Stockbroker Grapevine

题目链接:http://poj.org/problem?id=1125 分析:题意是求最小总时间.则我们要利用的也应该是任何两个人之间传递的最小时间,所以,先要用floyd算法处理.然后,发出这个消息时,有n种选择(n个人),假如先传给i, 那么map[i][1......n] (map[i][j]表示i传到j的最小时间) 中的最大那个,假如是x[i],那么这种情况下x[i]是肯定最后知道的,

PWZER 923

POJ1125 Stockbroker Grapevine【Floyd】

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 spre

胡小涛的博客 276

POJ 1125 Stockbroker Grapevine floyd水题

传送门:POJ1125 题意:有n个人,给出他们之间互相传送信息需要的时间,让你选出某个人,使信息他开始传遍所有人所需的时间最少。求这个人和所需的最短时间。 思路:用floyd求出任意两人之间的最短路,然后筛选一遍就好了。当然也可以用dijkstra或者spfa,不过思路大体相同,算法不同罢了。 代码: #include #include #include #include #includ

WA是一笔财富 291

POJ 1125 Stockbroker Grapevine(Floyd)

题目地址:http://poj.org/problem?id=1125 题意:有一群买股票的人,如何从中间选择一个人使得所有人都知道这个消息的时间最短 思路:先把N个人中最短路径中最长的算出来,再从N个人最长的路径中找出最短的 AC代码: #include #include #include using namespace std; const int inf = 0x3f3f3f3

Java识堂,一个有干货的微信公众号 333

【POJ 1125】Stockbroker Grapevine

【POJ 1125】Stockbroker Grapevine 最短路 只是这题数据非常水。。主要想大牛们试试南阳OJ同题 链接例如以下: http://acm.nyist.net/JudgeOnline/talking.php?pid=426&page=2 数据增大非常多 用到非常多东西才干过 (弱没过,。。 这题就是求最短路寻找全部通路中最大权的最...

aofan9566的博客 147

POJ1125 Stockbroker Grapevine Floyd算法

题目大意:由n位股票经纪人传播股票(编号1到n),每位股票经纪人都可以向m位同事传播(经纪人之间互为同事,但传播是单向的),传播时需花费t个时间单位(如果2号和3号都是1号经纪人的同事,1号向2号传播需要5个时间单位,向3号传播需要4个时间单位,那么1号可以在5个时间单位的时间内向2号和3号同时传播);现在告诉你每位经纪人和其同事的信息(信息包括同事的编号和传播需要的时间单位),问你想要在最短的时

AC_Gibson的专栏 695

最短路poj 1125

题目:poj1125Stockbroker Grapevine 题意:此题题意远比题目难 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时,输入数据结束),然后接下来N行描述第i(1 分析:说的很清楚了,最短路算法基本都能水过,可以选熟悉的用 强调:floyd算法用前一定初始化为INF,否则会很惨。 代码: #include

大神养成中..... 7777

poj1125 Stockbroker Grapevine Floyd算法

问题描述 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 st...

战场医疗兵 315

POJ 1125-Stockbroker Grapevine(floyd)

E - Stockbroker Grapevine Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1125 Appoint description:  System Crawler  (2015-11-18)

梧桐下的四叶草 554
上一篇: poj-2253-Frogger-最短路
下一篇: poj-2240-Arbitrage-最短路 BF
RIPwangh
博客等级 码龄12年 42粉丝 172原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值