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的速度不一定相等。 给定一个消息,并不一定能够传遍所有的股票经纪人,因为股票经纪人可能形成一座座“孤岛”,使得信息无法送达。 现在给定 阅读详情

相关推荐

【RT-Thread】从零到一:RT-Thread Studio工程创建与程序下载全流程实战

本文详细介绍了RT-Thread Studio开发环境的安装与使用,从工程创建到程序下载的全流程实战指南。通过具体案例演示了如何在STM32平台上快速开发RT-Thread应用,包括时钟配置、内存优化、构建调试等关键技巧,帮助开发者高效完成嵌入式系统开发。

weixin_30336061的博客 549

【POJ 1125】Stockbroker Grapevine

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

aofan9566的博客 147

压电陶瓷传感器避坑指南:实测阻抗匹配对信号输出的影响(附示波器调试技巧)

本文深入探讨压电陶瓷传感器在工业振动监测中的阻抗匹配问题,通过等效电路模型和实测数据揭示负载阻抗对信号输出的关键影响。文章提供从元件选型到示波器调试的完整解决方案,特别强调100kΩ以上负载阻抗的重要性,并分享JFET缓冲器设计和PCB布局的实用技巧,帮助工程师避免信号失真和输出不稳定问题。

ooo22的博客 522

poj 1125 Stockbroker Grapevine

floyd

我要吃熊猫 341

用LTspice仿真CMOS反相器功耗?这份避坑指南能省你3天调试时间

本文详细介绍了如何使用LTspice准确仿真CMOS反相器的功耗,包括动态功耗、短路功耗和静态功耗的测量技巧。通过工程实践指南,帮助电子工程师避开常见陷阱,优化仿真参数设置,提升仿真结果的可靠性,节省调试时间。

w7x8y9z的博客 194

2026年ERP选型实战:按规模分档,避开成本与实施陷阱

企业资源计划(ERP)是现代企业数字化转型的核心系统,它将财务、供应链、制造、人力等业务整合到统一平台。随着云计算和人工智能技术的发展,ERP已从传统本地部署的记录工具演变为SaaS订阅制、具备AI辅助决策能力的智能运营平台。不同规模企业在选型时的关注点差异巨大:小微企业追求轻量化和快速出报表,中型企业需要在流程标准化与业务灵活性间取得平衡,大型集团则注重多法人管控和数据治理。此外,制造、电商、工程等行业对ERP的模块要求也各有侧重,成本核算数据跑不通更是普遍痛点。如何结合企业规模与行业特征,制定合理的选型

weixin_34320724的博客 382

POJ 1125 Stockbroker Grapevine //Floyd算法

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

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

基于STM32的Modbus TCP多主站数据监测

Modbus TCP通信协议在STM32上实现,STM32作为服务器采集内部传感器数据,并通过ADC进行转换,存入寄存器。两个PC机作为客户端访问服务器,服务器通过Socket通信实现监听连接,将数据发送给客户端。

hyp12347的博客 4303

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的专栏 802

【微服务】SpringBoot 整合Kafka 项目实战操作详解

SpringBoot 整合Kafka 实战操作详解

congge 5587

C# WPS操作PPT,全屏,缩率图,备注,跳转播放

本文介绍了一个使用C#开发的PPT操作工具,主要功能包括检测当前打开的PPT文件、获取选中PPT路径、指定播放PPT、获取PPT页面序号和缩略图、提取备注内容等。文章展示了操作界面效果图,并重点解决了用户手动退出PPT后重新获取路径时报错的问题。核心代码实现了通过WPS API进行PPT文件的打开、全屏播放、页面跳转、获取当前页位置等功能,同时支持生成PPT缩略图预览和备注信息提取。当用户未通过工具按钮打开PPT时,程序会自动初始化PPT信息确保功能正常使用。

遇见--专栏 318

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

uniapp [全端兼容] - 实现人脸识别对比+人脸相似度,从相册选择或拍照上传两张图片进行人脸对比得到人脸相似度及判断是否是同一个人,人脸活体检测及对比(免费纯前端方案+调用第三方API接口方案)

uniApp人脸对比 人脸对比识别 人脸对比相似度,uniapp实现获取手机摄像头权限,调用相机拍照实现人脸识别相似度对比,uniapp实现人脸识别对比,计算两张人脸的相似度,从而判断是否同一个人,并给出相似度评分。uniapp H5网页如何实现人脸相似度比对,uniapp纯前端怎么对比两张图片的相似度,计算两幅图像的相似度,图像相似度对比方法,UNI-APP人脸相似度对比,快速识别两张照片的相似程度(用百分比)图片相似度对比在线测试,图片相似度对比,uniapp微信小程序人脸相似度对比分析,uniapp

🏆 前端领域优质创作者 5030

POJ 1125 Stockbroker Grapevine(Floyd)

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

code 1056

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

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

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

POJ 刷题系列:1125. Stockbroker Grapevine

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

Demon-初来驾到 606

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

poj 1125 Stockbroker Grapevine

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

CandyLien 429

最短路(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(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的博客 334

poj1125 Stockbroker Grapevine

poj1125 Stockbroker Grapevine

钟子悦的博客 364

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的博客 392
上一篇: 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、付费专栏及课程。

余额充值