【POJ】Stockbroker Grapevine

初级->图算法->最短路 poj 1125 Stockbroker Grapevine Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21767 Accepted: 11857 Description Stockbrokers are known to overreact to rumours. You hav 阅读详情

Problem here

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
0

Sample Output

3 2
3 10

Solution

Floyd

#include <iostream>
#include <memory.h>
#define INF_NUM 99999999
using namespace std;

int n;
int dis[200][200];

int main(){
    while(cin >> n){
        if(n == 0)
            break;
        for(int i = 1; i <= n; i++){
            for(int j= 1; j <= n; j++)
                dis[i][j] = INF_NUM;
            dis[i][i] = 0;
        }
        for(int i = 1; i <= n; i++){
            int t, x, w;
            cin >> t;
            for(int j = 0; j < t; j++){
                cin >> x >> w;
                dis[i][x] = w;
            }
        }

        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                for(int k = 1; k <= n; k++)
                    if(dis[j][i] + dis[i][k] < dis[j][k])
                        dis[j][k] = dis[j][i] + dis[i][k];

        int ans = INF_NUM;
        int ans_pos;
        bool ok = false;
        for(int i = 1; i <= n; i++){
            int maxlen = 0;
            bool check = true;
            for(int j = 1; j <= n; j++){
                if(dis[i][j] == INF_NUM){
                    check = false;
                    break;
                }else if(dis[i][j] > maxlen){
                    maxlen = dis[i][j];
                }
            }
            if(check){
                ok = true;
                if(ans > maxlen){
                    ans = maxlen;
                    ans_pos = i;
                }
            }
        }
            if(ok){
                cout << ans_pos << " " << ans << endl;
            }else{
                cout <<"disjoint" << endl;
            }

        }

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

相关推荐

(8)机器人动力学

机器人是一个具有多输入多输出的复杂动力学系统,存在严重的非线性,需要非常系统的方法对机器人进行动力学研究。常用的机器人动力学建模方法有:Lagrange(拉格朗日)动力学方法、Newton-Euler(牛顿-欧拉)动力学方法、Gauss(高斯)动力学方法、Kane(凯恩)动力学方法等。机器人动力学研究的是机器人的运动和作用力之间的关系。机器人的动力学问题包括动力学正问题和动力学逆问题。动力学正问题是对于给定的关节驱动力......

rouyu308的博客 9498

什么是木马?一篇文章给你讲清楚

从技术角度分析,发送文件类的QQ蠕虫是以前发送消息类QQ木马的进化,采用的基本技术都是搜寻到聊天窗口后,对聊天窗口进行控制,来达到发送文件或消息的目的。然后,删除木马病毒的文件和注册表项,确保彻底清除。因此,用户在使用电脑时应保持警惕,避免下载和执行未知来源的文件,及时更新系统和软件,以要杀掉木马病毒,你需要采取一系列步骤来清除系统中的恶意软件。运行在服务端的木马程序首先隐匿自己的行踪,伪装成合法的通信程序,然后采用修改系统注册表的方法设置触发条件,保证自己可以被执行,并且可以不断监视注册表中的相关内容。

2401_82590480的博客 1万+

calibre QRC提取寄生参数

typical将上面的文件QCI_flow里面的文件 在Cp 到当前 ,其实应该是某几个文件,但是我给忘记了 就全cp过来了 ,无影响,不过也希望大佬指正。

2202_75711937的博客 1516

攻防基础-木马病毒介绍

一、什么是木马? 木马病毒是计算机黑客用于远程控制计算机的程序,一般的木马病毒程序主要是寻找计算机后门,伺机窃取被控计算机中的重要文件等等。木马病毒还可以对被控计算机实施监控、资料修改等非法操作。 二、木马病毒的特征 1、隐蔽性极强 木马病毒一般占用空间很小,不易找到。 2、自动运行性 木马病毒会随着计算机系统的启动而自动启动。 3、欺骗性 木马病毒一般都会使用一些手段伪装成一些合法APP,防止一眼就被计算机用户认出。 4、自动恢复 当木马的某一功能模块丢失时,它能够自动恢复成丢失

m0_73995538的博客 6628

保姆级教程:用GROMACS的FEP方法计算小分子结合自由能(附完整mdp配置)

本文提供了一份详细的GROMACS自由能微扰(FEP)计算教程,涵盖从系统准备、参数配置到结果分析的全流程。通过具体案例演示如何计算小分子结合自由能,包括λ窗口设计、动力学参数优化及并行化执行技巧,帮助研究者克服FEP计算中的常见问题,获得可靠的自由能数据。

weixin_30598225的博客 352

单细胞基因可视化之热图的根本改造2

我们前面已经说过了单细胞marker/或者其他任意基因的热图的简单修饰(单细胞基因可视化之热图改造修饰1),仅仅是基于颜色和DoHeatmap函数的参数修饰。那么要对热图进行根本的改造,关键点在于提取表达矩阵,然后对分组进行注释,就可以使用heatmap或者ComplexHeatmap来做图了。 首先计算marker基因,然后选择自己需要展示的基因。 library(Seurat) library(stringr) library(dplyr) all.markers <- Find

qq_42090739的博客 6676

木马病毒简介

病毒的分类:   很多时候大家已经用杀毒软件查出了自己的机子中了例如Backdoor.RmtBomb.12 、Trojan.Win32.SendIP.15 等等这些一串英文还带数字的病毒名。   只要掌握一些病毒的命名规则,就能通过杀毒软件的报告中出现的病毒名来判断该病毒的一些公有的特性。   世界上那么多的病毒,反病毒公司为了方便管理,他们会按照病毒的特性,将病毒进行分类命名。虽然每个反病...

weixin_30652271的博客 6581

无人机避障——Mid360+Fast-lio感知建图+Ego-planner运动规划(胎教级教程)

本工作将 Mid360 激光雷达、Fastlio-SLAM 和 Ego-Planner 集成,实现无人机的环境感知、定位建图和运动规划(仿真过程)—— 胎教级教程。

weixin_45390670的博客 1万+

(1)【木马病毒】认识木马:原理、分类、入侵

【木马病毒-初识】

1万+

蓝桥杯算法:打印图形——六芒星

【输入格式】 输入一行包含一个整数 n。 【输出格式】 输出一个六芒星,表示满足题意的图形。 【样例输入】 3 4 【样例输出】 【评测用例规模与约定】 对于所有评测用例,1 ≤ n ≤ 20。 总结: 第一次做图形题,做了蛮久,图形题有很多的方式去完成,它考验的是你能不能找到更简单的那一种方式. 我初看到这个图形,第一种想法是把这个六芒星当做六个小三角形来做,然后以某种规则排列一下,就能做出来,但是尝试了一下感觉太麻烦了。 然后我的第二种想法是,这个图形是对称图形,怎么能写出一半吗? 这样另一半想办

KeepCodeing 3835

在Qt中集成VTK和PCL:实现数据可视化的完整指南

在现代软件开发中,数据可视化至关重要。将VTK(Visualization Toolkit)和PCL(Point Cloud Library)集成到Qt环境里,能为开发者提供强大的可视化解决方案。本文将深入讲解如何在Qt中读取PCL文件,展示VTK模型和PCL数据,适合想要在Qt项目中实现数据可视化的开发者。

轩宇的博客 916

1002: Stockbroker Grapevine

<br />1002: Stockbroker GrapevineResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE3s8192K2595774Standard<br />Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers

kongming_acm的专栏 555

Fluent验证案例03:管道中湍流流动压降计算——采用kw-sst模型计算压降更为准确。

阅读(4053) 评论(0)本案例利用Fluent计算管道中湍流流动压降。

qq_15963745的博客 874

POJ 1125 Stockbroker Grapevine

POJ 1125 Stockbroker Grapevine #include <iostream> #include <fstream> #include <string> #include <algorithm> ...

dayong9372的博客 117

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

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

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

【POJ 1125】Stockbroker Grapevine

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

aofan9566的博客 147

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

poj 1125 Stockbroker Grapevine

floyd

我要吃熊猫 340

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

POJ 1125 Stockbroker Grapevine //Floyd算法

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

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

POJ 1125 Stockbroker Grapevine(Floyd)

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

code 1053

poj1125 Stockbroker Grapevine 最短路 dijkstral + 优先队列

// poj1125 Stockbroker Grapevine 最短路 dijkstral + 优先队列 // // 一个模板吧,留着纪念 #include #include #include #include #include using namespace std; typedef pair P; const int MAX_N = 108; const i

TIMELIMITE的专栏 800

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

POJ 刷题系列:1125. Stockbroker Grapevine

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

Demon-初来驾到 603

poj 1125 Stockbroker Grapevine

poj  1125  Stockbroker Grapevine   #include #include #include #include using namespace std; int cost[102][102]; int n; void flo

CandyLien 425

poj 1125 Stockbroker Grapevine(floyd)

http://blog.youkuaiyun.com/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

最短路(Floyd_Warshall) POJ 1125 Stockbroker Grapevine

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

weixin_30558305的博客 81
上一篇: 【POJ】Jungle Roads
下一篇: 玩脫了的最小生成樹
「已注销」
博客等级 码龄12年 1粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值