【Floyd】POJ1125-Stockbroker Grapevine
水题,裸的Floyd。最后要求遍历一遍图的最短路径,只需要枚举将当前每一个点作为起始点。如果它不能到达其中的某一点,则该点不可能作为起始点;否则,由该点开始遍历全图的最短路径是到所有点距离中的最大值。最终结果就是这些最大值中的最小值。
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=+;
const int INF=;
int map[MAXN][MAXN]; int main()
{
int n;
while (scanf("%d",&n))
{
if (n==) break;
for (int i=;i<n;i++)
for (int j=;j<n;j++) map[i][j]=INF; for (int i=;i<n;i++)
{
int m;
scanf("%d",&m);
for (int j=;j<m;j++)
{
int people,time;
scanf("%d%d",&people,&time);
map[i][people-]=time;
}
} for (int k=;k<n;k++)
for (int i=;i<n;i++)
for (int j=;j<n;j++)
if (i!=j && k!=i && k!=j && map[i][j]>map[i][k]+map[k][j])
{
map[i][j]=map[i][k]+map[k][j];
} int ans=INF,ansb;
for (int i=;i<n;i++)
{
bool reach=true;
int maxlen=-;
for (int j=;j<n && reach;j++)
{
if (i!=j && map[i][j]==INF) reach=false;
if (i!=j && map[i][j]>maxlen) maxlen=map[i][j];
}
if (reach && maxlen<ans)
{
ans=maxlen;
ansb=i;
}
}
if (ans==INF) cout<<"disjoint";else cout<<ansb+<<' '<<ans;
cout<<endl;
} return ;
}
【Floyd】POJ1125-Stockbroker Grapevine的更多相关文章
- BZOJ1599 find the mincost route 【floyd】
题目链接 BZOJ1599 题解 最小环模板?周末了养生一下[逃] 解释一下原理 \(floyd\)算法每一轮求出以\([1,k]\)为中介点的最短路 我们对于一个环,考虑环上编号最大的点,在\(k\ ...
- 【Floyd】珍珠
[题目描述] 有n颗形状和大小都一致的珍珠,它们的重量都不相同.n为整数,所有的珍珠从1到n编号.你的任务是发现哪颗珍珠的重量刚好处于正中间,即在所有珍珠的重量中,该珍珠的重量列(n+1)/2位.下面 ...
- POJ 1125 Stockbroker Grapevine【floyd】
很裸的floyd #include<cstdio> #include<string.h> #include<algorithm> #define maxn 201 ...
- poj1125 Stockbroker Grapevine Floyd
题目链接:http://poj.org/problem?id=1125 主要是读懂题意 然后就很简单了 floyd算法的应用 代码: #include<iostream> #include ...
- POJ1125-Stockbroker Grapevine【Floyd】(模板题)
<题目链接> 题目大意: 题目可能有多组测试数据,每个测试数据的第一行为经纪人数量N(当N=0时,输入数据结束),然后接下来N行描述第i(1<=i<=N)个经纪人与其他经纪人的 ...
- POJ1125 Stockbroker Grapevine
Description Stockbrokers are known to overreact to rumours. You have been contracted to develop a me ...
- 【Floyd】文化之旅
[NOIP2012]文化之旅 题目描述 有一位使者要游历各国,他每到一个国家,都能学到一种文化,但他不愿意学习任何一 种文化超过一次(即如果他学习了某种文化,则他就不能到达其他有这种文化的国家).不 ...
- HDU 1869 六度分离【floyd】
题意:给出n个人,m个关系,问是否满足任意两个人之间的距离通过6个人就可以连接 用floyd就可以了,注意距离是大于7 #include<iostream> #include<cst ...
- UVa 821 Page Hopping【Floyd】
题意:给出一个n个点的有向图,任意两个点之间都相互到达,求任意两点间最短距离的平均值 因为n很小,所以可以用floyd 建立出图,然后用floyd,统计d[][]不为0且不为INF的边的和及条数,就可 ...
随机推荐
- bootstrap基本用法
进入中文官网:http://www.bootcss.com 开始第一个Demo 准备工作: (1)进入bootstrap中文官网,点击起步 (2)下载生产环境 下载好的文件是一 ...
- adb端口被占用解决
解决ADB端口占用问题 方式一5037为adb默认端口,若5037端口被占用,查看占用端口的进程PIDC:\Users\wwx229495>netstat -aon|findstr 5037 ...
- perl 复制exe文件的简单方法
use warnings; use strict; open EXE, "cmd.exe" or die "Can not open cmd.exe:$!\n" ...
- 实战手工注入某站,mssql注入
昨天就搞下来的,但是是工具搞得,为了比赛还是抛弃一阵子的工具吧.内容相对简单,可掠过. 报错得到sql语句: DataSet ds2 = BusinessLibrary.classHelper.Get ...
- python基础===两个list之间移动元素
首先我们先了解一下list的几个常用函数: a = [123,456,"tony","jack"] #list中增加元素a.append("www&q ...
- Jquery动态添加元素并给元素增加onchange相应
动态添加元素: $select = $("<select></select>"); $("<option></option> ...
- LeetCode解题报告—— Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- 微信小程序-表格形式如何布局?
微信小程序没有现成的table标签,该怎么布局呢? <view class="my-grids"> <block wx:for="{{grids}}&q ...
- javascript高程笔记:逻辑与和逻辑或
逻辑与和或 逻辑与 当 && 前后两个操作数都是布尔值,无可厚非,同时为true才为true.与其他强类型语言不同的是,javascript逻辑与前后的操作数可以应用于任何类型. 而且 ...
- vue验证码组件
1.效果图 2.全部代码: <template> <div class="join_formitem"> <label class="enq ...