zoukankan      html  css  js  c++  java
  • poj 1125Stockbroker 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 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个点,m条边,从任何一点出发求到达所有人中的最短距离是多少,求所有路劲中的最小值,
    我们可以提前用floyd把所有路径求出,然后判断即可
    View Code
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <math.h>
     4 #define INF 0x7f7f7f7
     5 #define N 110
     6 int map[N][N],n;
     7 void init()
     8 {
     9     int i,j;
    10     for(i=0;i<=n;i++)
    11     {
    12         for(j=0;j<=n;j++)
    13             map[i][j]=INF;
    14         map[i][i]=0;
    15     }
    16 }
    17 void floyd()
    18 {
    19     int i,j,k;
    20     for(k=1;k<=n;k++)
    21         for(i=1;i<=n;i++)
    22             for(j=1;j<=n;j++)
    23                 if(map[i][j]>map[i][k]+map[k][j])
    24                     map[i][j]=map[i][k]+map[k][j];
    25 }
    26 int main()
    27 {
    28     int m,i,j;
    29     int a,b;
    30     while(scanf("%d",&n)&&n)
    31     {
    32         init();
    33         for(i=1;i<=n;i++)
    34         {
    35             scanf("%d",&m);
    36             for(j=0;j<m;j++)
    37             {
    38                 scanf("%d%d",&a,&b);
    39                 map[i][a]=b;
    40             }
    41         }
    42         floyd();
    43         int minn=INF,num;
    44         for(i=1;i<=n;i++)
    45         {
    46             int maxx=-1;
    47             for(j=1;j<=n;j++)
    48             {
    49                 if(map[i][j]>maxx)
    50                     maxx=map[i][j];
    51             }
    52             if(maxx<minn)
    53             {
    54                 minn=maxx;
    55                 num=i;
    56             }
    57         }
    58         if(minn==INF)
    59             printf("disjoint\n");
    60         else
    61             printf("%d %d\n",num,minn);
    62     }
    63     return 0;
    64 }
  • 相关阅读:
    并发实现-Callable/Future 实现返回值控制的线程
    Sql Server查询,关闭外键约束的sql
    Kettle-动态数据链接,使JOB得以复用
    Python爬虫实践~BeautifulSoup+urllib+Flask实现静态网页的爬取
    javaAPI操作Hbase
    Linux下的网络环境配置
    DataCleaner(4.5)第二章
    DataCleaner(4.5)第一章
    SpringBoot 使用 MyBatisPlus-Generator 快速生成model实体类
    Java 使用hutool工具类代替commons-text进行Json 中文 Unicode转换
  • 原文地址:https://www.cnblogs.com/wilsonjuxta/p/2963762.html
Copyright © 2011-2022 走看看