https://vjudge.net/problem/POJ-1125

题意:

题意不是很好理解,首先输入一个n,表示有n个股票经纪人,接下来输入n行,每行第一个数m为该股票经纪人认识的经纪人数,然后输入m对数(a,t),表示第i个经纪人把消息传给第a个经纪人所需要的时间。

计算将消息传遍所有人所需要的最少时间。

思路:

起点任意,用floyd比较好。因为floyd求出的是每两点之间的最短路,所以最后计算最小时间时,需要先取最大值,比如说1号经纪人为起点,因为谁都可能为终点,所以枚举所有人,将最大时间作为最小时间,这个应该不难理解。

 #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; const int maxn = + ;
const int INF = 0x3f3f3f3f; int n;
int d[maxn][maxn]; void floyd()
{
for (int k = ; k <= n;k++)
for (int i = ; i <= n;i++)
for (int j = ; j <= n; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int x, a, t;
while (~scanf("%d", &n) && n)
{
for (int i = ; i <= n; i++)
{
d[i][i] = ;
for (int j = ; j < i; j++)
d[i][j] = d[j][i] = INF;
} for (int i = ; i <= n; i++)
{
scanf("%d", &x);
while (x--)
{
scanf("%d%d", &a, &t);
d[i][a] = t;
}
} floyd();
int stock;
int ans = INF;
for (int i = ; i <= n; i++)
{
int MAX = ;
for (int j = ; j <= n; j++)
{
if (i == j) continue;
MAX = max(MAX, d[i][j]);
}
if (ans > MAX)
{
ans = MAX;
stock = i;
}
}
if (ans == INF)
printf("disjoint\n");
else
printf("%d %d\n", stock, ans);
}
return ;
}

POJ Stockbroker Grapevine(floyd)的更多相关文章

  1. Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意: 首先,题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时, 输入数据结束),然后接下来N行描述第i(1< ...

  2. POJ 1125 Stockbroker Grapevine(floyd)

    http://poj.org/problem?id=1125 题意 : 就是说想要在股票经纪人中传播谣言,先告诉一个人,然后让他传播给其他所有的经纪人,需要输出的是从谁开始传播需要的时间最短,输出这个 ...

  3. POJ 2253 Frogger(floyd)

    http://poj.org/problem?id=2253 题意 : 题目是说,有这样一只青蛙Freddy,他在一块石头上,他呢注意到青蛙Fiona在另一块石头上,想去拜访,但是两块石头太远了,所以 ...

  4. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

  5. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  6. POJ 2253 Frogger (Floyd)

    Frogger Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:57696   Accepted: 18104 Descript ...

  7. POJ 2431 Expedition(探险)

    POJ 2431 Expedition(探险) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] A group of co ...

  8. POJ 3414 Pots(罐子)

    POJ 3414 Pots(罐子) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 You are given two po ...

  9. POJ 3281 Dining (网络流)

    POJ 3281 Dining (网络流) Description Cows are such finicky eaters. Each cow has a preference for certai ...

随机推荐

  1. 【黑金ZYNQ7000系列原创视频教程】02.视频接口——hdmi编码输出实验

    黑金论坛地址: http://www.heijin.org/forum.php?mod=viewthread&tid=36636&extra=page%3D1 爱奇艺地址: http: ...

  2. 【BZOJ4401/3004】块的计数/吊灯 乱搞

    [BZOJ4401]块的计数 Description 小Y最近从同学那里听说了一个十分牛B的高级数据结构——块状树.听说这种数据结构能在sqrt(N)的时间内维护树上的各种信息,十分的高效.当然,无聊 ...

  3. (转)大数据量下的SQL Server数据库优化

     在SQL Server中,默认MDF文件初始大小为5MB,自增为1MB,不限增长,LDF初始为1MB,增长为10%,限制文件增长到一定的数目:一般设计中,使用SQL自带的设计即可,但是大型数据库设计 ...

  4. LightOj 1422 Halloween Costumes(区间DP)

    B - Halloween Costumes Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit ...

  5. IIS中User-mode caching引起的Cache-Control不为public的问题

    在IIS的Output caching中如果启用了User-mode caching将引起Cache-Control为no-cache,从而造成页面不能被浏览器或代理服务器缓存. web.config ...

  6. 禁止输入emoji表情

    三个文本框textField UITextView都要禁止苹果自带emoji 后来发现是原来写的方法不能覆盖所有的表情,新增的表情过滤不掉,只好再加了一个方法 http://www.jianshu.c ...

  7. Qt 模拟鼠标点击(QApplication::sendEvent(ui->pushbutton, &event0);)

    QPoint pos(0,0);QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton, Qt ...

  8. sql server学习路径地址

    联机丛书2005:https://docs.microsoft.com/zh-cn/previous-versions/sql/sql-server-2005/ms130214(v=sql.90) 联 ...

  9. SDWebimage清空缓存

    清空缓存 - (void)clearTmpPics{ [[SDImageCache sharedImageCache] clearDisk]; [[SDImageCache sharedImageCa ...

  10. android gson使用

    第一步注册:  compile 'com.google.code.gson:gson:2.6.2' 第二步初始化: Gson gson = new GsonBuilder() .setLenient( ...