UVa 821 网页跳跃(Floyd)
https://vjudge.net/problem/UVA-821
题意:
给出一个有向图,任意两点都可相互到达,求任意两点的最短距离的平均值。
思路:
求两点的最短距离,用Floyd算法很方便,最后加起来算个平均值即可。
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std; const int INF = ; int x, y;
int d[][]; void Floyd()
{
for (int k = ; k <= ;k++)
for (int i = ; i <= ;i++)
for (int j = ; j <= ; j++)
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int kase = ;
while (cin >> x >> y && (x!= || y!=))
{
for (int i = ; i <= ;i++)
for (int j = ; j <= ;j++)
if (i == j) d[i][j] = ;
else d[i][j] = INF; do
{
d[x][y] = ;
} while (cin >> x >> y && (x!= || y!=));
Floyd();
double ans = ;
int count = ;
for (int i = ; i <= ;i++)
for (int j = ; j <= ; j++)
{
if (i!=j && d[i][j] < INF)
{
count++;
ans += d[i][j];
}
}
printf("Case %d: average length between pages = %.3f clicks\n", ++kase, ans / count);
}
}
UVa 821 网页跳跃(Floyd)的更多相关文章
- UVA 821 Page Hopping 网页跳跃(BFS,简单)
题意: 给一个无权有向图,可认为边的长度为1,求两点间的平均长度(即所有点对的长度取平均),保留3位小数.保证任意点对都可达. 思路: 简单题.直接穷举每个点,进行BFS求该点到其他点的距离.累加后除 ...
- UVa 821 Page Hopping【Floyd】
题意:给出一个n个点的有向图,任意两个点之间都相互到达,求任意两点间最短距离的平均值 因为n很小,所以可以用floyd 建立出图,然后用floyd,统计d[][]不为0且不为INF的边的和及条数,就可 ...
- 紫书 习题 11-1 UVa 821 (Floyd)
水题, Floyd一遍就完了. #include<cstdio> #include<algorithm> #define REP(i, a, b) for(int i = (a ...
- UVa 104 - Arbitrage(Floyd动态规划)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVA - 10048 Audiophobia (Floyd应用)
题意:求出两点之间所有路径最大权值的最小值. 思路:转变一下Floyd的形式即可: 注意:注意初始化问题,还有UVA奇葩的输出形式. 代码如下: #include<iostream> #i ...
- UVa 10048 - Audiophobia(Floyd变形)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 567 Risk【floyd】
题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=508">https://uva ...
- uva oj 567 - Risk(Floyd算法)
/* 一张有20个顶点的图上. 依次输入每个点与哪些点直接相连. 并且多次询问两点间,最短需要经过几条路才能从一点到达另一点. bfs 水过 */ #include<iostream> # ...
- UVA 247 电话圈(Floyd传递闭包+输出连通分量)
电话圈 紫书P365 [题目链接]电话圈 [题目类型]Floyd传递闭包+输出连通分量 &题解: 原来floyd还可以这么用,再配合连通分量,简直牛逼. 我发现其实求联通分量也不难,就是for ...
随机推荐
- 【剑指offer】旋转数组的最小数字
一.题目: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个 ...
- CentOS6.5 升级 Python 2.7 版本
转载请注明出处http://write.blog.csdn.net/mdeditor 目录 目录 前言 安装Python-279 解决YUM与Python279的兼容问题 前言 CentOS 6.5中 ...
- openssl version 查看openssl 版本出现openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory,怎么办
查看openssl版本, 解决办法: ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/li ...
- 正态分布及3Sigma原理
针对这个问题,用一两句话是难以说清楚的,这是数理统计学的内容,当质量特性呈正态分布时(实际上,当样本足够大时,二项分布.泊松分布等均趋近于正态分布),3Sigma水平代表了99.73%的合格率
- Set keys=Map.keyset()
目前只有Map和Properties要用到keyset()方法 Properties:指JDBC时候的连接数据库,把数据库的参数提取到配置文件时用到, 通俗的讲,Properties专门用来读取配置文 ...
- php unset()函数销毁变量但没有实现内存释放
<?PHP $a = "hello";$b = &$a;unset( $b );echo $a; // 输出 helloecho $b; // 报错$b = &quo ...
- Summary: sorting Algorithms
Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item a ...
- chkconfig添加进入服务后,出现的现象
比如在php-fpm添加服务中,一部分脚步如下 #!/bin/sh # # php-fpm - this script starts and stops the php-fpm ...
- java的时间处理
采用joda.time库 gradle,可以简化calendar的 compile "joda-time:joda-time:2.7" 例子:http://blog.csdn.ne ...
- centos6更改密码
创建新用户 创建一个用户名为:zhangbiao [root@localhost ~]# adduser zhangbiao 为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略: [r ...