POJ 1125 Stockbroker Grapevine(DP)
来源:互联网 发布:网络厂商排名 编辑:程序博客网 时间:2024/06/03 08:16
题意:Stockbrokers要散布一个股票的谣言,谣言只能在相互认识的人中传递,给出人与人的关系(是否认识),以及传言在某两个认识的人中传递所需的时间。求出以哪个人作为散布谣言的起点,能使得所有人都受到谣言的时间最短。
思路:先floyd求出传递闭包,然后枚举每个人,求出传递给其他人的最大时间的最小值,保存下答案即可
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 105;const int INF = 0x3f3f3f3f;int n, g[N][N];int main() { while (~scanf("%d", &n) && n) {int tot;memset(g, INF, sizeof(g));for (int i = 1; i <= n; i++) { g[i][i] = 0; scanf("%d", &tot); int a, b; while (tot--) {scanf("%d%d", &a, &b);g[i][a] = min(g[i][a], b); }}for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]);} }}int ans = INF, ansv;for (int i = 1; i <= n; i++) { int s = -INF; for (int j = 1; j <= n; j++)s = max(s, g[i][j]); if (s < ans) {ans = s;ansv = i; }}if (ans == INF) printf("disjoint\n");else printf("%d %d\n", ansv, ans); } return 0;}
0 0
- POJ 1125 Stockbroker Grapevine(DP)
- poj 动态规划DP - 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- Poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125-Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- POJ 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- poj 1125 Stockbroker Grapevine
- mysql的安装
- 我的第二个APP上架了····
- 从把三千行代码重构成15行代码谈起
- 论REST架构与传统MVC
- sprintf函数的使用
- POJ 1125 Stockbroker Grapevine(DP)
- Hdu 2196 题解
- 微博用户相似度分析
- 使用Zlib库进行文件的压缩和解压
- Android - 确认ImageView的图片是否加载成功
- Android之ndk
- 用JAVA 实现“生产者-消费者”问题
- 不用修改任何核心文件,实现dede模板pc和手机访问的页面制作教程
- 计算机图形学_复习整理(3)