POJ 1125 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 阅读详情
Stockbroker Grapevine
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 23783 Accepted: 13067

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

题意:有1条谣言,n个证券经理,每个经理可以向其他人转播谣言,(每个经理的传播数任意)。而每个经理和其他经理传播时,需要时间(如a对b传播需要3,a对c传播需要4)。问从哪个经理作为起点,能够传播的人数最多,并且时间最短。


其实这道题比较像是多点对之间的最短路,(首先要满足传播的人数最多,其次要满足在所有最短路当中的最大值最小。。好绕口)

那我采用了Floyd来算多源最短路,之后再找到起点和最短时间

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define maxn 105
#define INF 1000000
using namespace std;
int n,map[maxn][maxn];
void init()
{
    int i,j;
    for (i=1; i<=n; i++)
    {
        for (j=1; j<=n; j++)
            map[i][j]=INF;
        map[i][i]=0;
    }
    for (i=1; i<=n; i++)
    {
        int t,a,b;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d%d",&a,&b);
            map[i][a]=b;
        }
    }
}
void floyd()
{
    int i,j,k;
    for (k=1; k<=n; k++)
        for (i=1; i<=n; i++)
            for (j=1; j<=n; j++)
                if (map[i][k]+map[k][j]<map[i][j])
                    map[i][j]=map[i][k]+map[k][j];
    k=0;
    int m=0,z=INF;
    /*
    for (i=1; i<=n; i++){
        for (j=1; j<=n; j++)
            cout<<map[i][j]<<" ";
        cout<<endl;
    }
    */
    for(i=1; i<=n; i++)
    {
        int p=0,t=0;
        for (j=1; j<=n; j++)
            if (map[i][j]!=INF)
            {
                if (map[i][j]>t) t=map[i][j];//用t来记录以每个经纪人为起点,传播的最长时间
                p++;//p来记录每个经纪人可以传多少其他人
            }
        if (p>m)//人数是第一个条件,所以人数大,就进行交换
        {
            m=p;
            k=i;
            z=t;
        }
        else if (p==m && t<z)//如果人数相同,就比较最长时间,取较短的
        {
            m=p;
            k=i;
            z=t;

        }
    }
    cout<<k<<" "<<z<<endl;
}
int main ()
{
    while(cin>>n)
    {
        if (n==0) break;
        init();
        floyd();
    }
    return 0;
}


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

相关推荐

Win11下CH340串口识别失败的终极排查指南:从驱动更新到硬件电路检查

本文提供了Windows 11系统下CH340串口芯片识别失败的全面排查指南。从驱动更新、系统设置等软件层面入手,逐步深入到USB线缆、电源测量等硬件连接检查,并重点剖析了硬件设计细节,如电源退耦电容容值对设备描述符请求的关键影响,最终帮助开发者系统性地定位并解决识别难题。

weixin_29174013的博客 590

【POJ 1125】Stockbroker Grapevine

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

aofan9566的博客 147

智能座舱架构与芯片 - (3) 硬件篇 上

在了解智能座舱的基本架构之后,我们有必要针对智能座舱域的硬件平台,软件平台,SOC等进行逐一介绍。从它们的整体结构中去认识最新的智能座舱组成部件,以及主要功能等。如上图,是中央计算-区域控制架构下的智能座舱硬件平台框架图,其中,智能座舱控制器CDC挂载在以太网交换机上,与其他车控域VDC,自驾域ADC,网联设备5G+V2X等通过以太网实现数据交互。而智能座舱域的外部硬件设备还包含有连接子系统音频子系统摄像头子系统显示子系统存储子系统功能安全子系统等。

joanna_xiao的博客 2400

poj 1125 Stockbroker Grapevine

floyd

我要吃熊猫 341

Habitat-baselines v0.1.7防踩坑手把手带你跑通(全网唯一)

Habitat-baselines v0.1.7防踩坑手把手带你跑通(全网唯一)

shannanshouyin的博客 1276

【WRF模拟】如何查看 WPS 的输入静态地理数据(二进制格式)?

如何查看 WPS 的输入静态地理数据(二进制格式)?

WW、forever的博客 633

POJ 1125 Stockbroker Grapevine //Floyd算法

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

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

AgentScope 2.0 扩展开发完全指南:从中间件到模型适配器的深度实践

本文系统讲解 AgentScope 2.0 框架的五大扩展机制,涵盖中间件系统的洋葱模型与钩子设计、ChatModelBase 基类与多供应商适配器开发、工作空间(本地/Docker/E2B)的抽象接口与生命周期管理、凭据工厂与 MCP 协议集成、以及工具协议与存储后端扩展。文中提供完整的架构图、代码示例与故障排查指南,帮助开发者快速掌握 AgentScope 的插件化扩展体系。

program哲学 295

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

TensorRT量化实战教程:从PTQ到QAT,让你的模型推理速度飞起来

无论是PTQ的“快速落地”,还是QAT的“精度极致”,TensorRT量化技术都能成为你模型部署路上的“性能引擎”。通过本教程的实战项目,你已掌握从技术原理到工程落地的全流程能力——现在,不妨将你的模型代入其中,亲眼见证它在速度与精度的双重提升中“焕发生机”。若你在实操中遇到任何卡点,随时可以针对具体问题交流,我会尽全力帮你突破量化部署的每一个瓶颈。

FJN110的博客 239

【EPS精品教程】EPS2016三维测图版安装教程(附EPS2016安装包下载地址)

EPS地理信息工作站是北京清华山维新技术开发有限公司历经十五年精心研发和打造,为满足“以地理信息服务为中心”的信息化测绘生产需求而推出的测绘生产活动多种业务模块集成化软件系统。主要功能有:(1)测绘与地理信息多业务模块集成管理;(2)多元多尺度多种类数据集成管理;(3)跨平台异构数据转换;(4)数据监理;(5)自动缩编与综合;(6)坐标转换与动态投影;(7)地理信息模板定制;(8)GIS地理信息描述与CAD图形表达一体化支持;(9)GIS数据库更新维护;(10)图形打印与地图出版。 一、安装过程 EP..

智慧空间实验室 2万+

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

ArcGIS Pro 3.4 二次开发 - 布局

本文介绍了在ArcGIS Pro SDK 3.4和.NET 8环境下操作布局工程项的相关方法。主要内容包括:引用布局工程项和关联布局,在新视图中打开或激活已有布局视图,引用活动布局视图,导入/移除布局工程项,创建基本布局或带参考线的自定义布局,修改布局页面尺寸,以及创建圆形图形元素等操作。重点演示了如何通过CIM(Core Infrastructure Model)进行高级布局配置,并详细说明了圆形图形元素的创建过程,包括几何构建、符号设置和图形生成。所有涉及UI线程的操作都遵循ArcGIS Pro SDK

Winemonk 795

POJ 1125 Stockbroker Grapevine(Floyd)

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

code 1054

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

POJ 刷题系列:1125. Stockbroker Grapevine

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

Demon-初来驾到 603

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

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

最短路(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 - 1125(Stockbroker Grapevine)

Stockbroker Grapevine 题目链接: http://poj.org/problem?id=1125 题目: Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39459   Accepted: 22024 Description Stockbrokers are k...

WQN20172674的博客 332

poj1125 Stockbroker Grapevine

poj1125 Stockbroker Grapevine

钟子悦的博客 363

Poj1125Stockbroker 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

5年Java后端研发,分享个人读书学习笔记。 438

【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

TLECODE的博客 391
上一篇: POJ 3723 Conscription
下一篇: POJ 1797 Heavy Transportation
SIO__Five
博客等级 码龄14年 29粉丝 225原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值