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)的更多相关文章

  1. UVA 821 Page Hopping 网页跳跃(BFS,简单)

    题意: 给一个无权有向图,可认为边的长度为1,求两点间的平均长度(即所有点对的长度取平均),保留3位小数.保证任意点对都可达. 思路: 简单题.直接穷举每个点,进行BFS求该点到其他点的距离.累加后除 ...

  2. UVa 821 Page Hopping【Floyd】

    题意:给出一个n个点的有向图,任意两个点之间都相互到达,求任意两点间最短距离的平均值 因为n很小,所以可以用floyd 建立出图,然后用floyd,统计d[][]不为0且不为INF的边的和及条数,就可 ...

  3. 紫书 习题 11-1 UVa 821 (Floyd)

    水题, Floyd一遍就完了. #include<cstdio> #include<algorithm> #define REP(i, a, b) for(int i = (a ...

  4. UVa 104 - Arbitrage(Floyd动态规划)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  5. UVA - 10048 Audiophobia (Floyd应用)

    题意:求出两点之间所有路径最大权值的最小值. 思路:转变一下Floyd的形式即可: 注意:注意初始化问题,还有UVA奇葩的输出形式. 代码如下: #include<iostream> #i ...

  6. UVa 10048 - Audiophobia(Floyd变形)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA 567 Risk【floyd】

    题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=508">https://uva ...

  8. uva oj 567 - Risk(Floyd算法)

    /* 一张有20个顶点的图上. 依次输入每个点与哪些点直接相连. 并且多次询问两点间,最短需要经过几条路才能从一点到达另一点. bfs 水过 */ #include<iostream> # ...

  9. UVA 247 电话圈(Floyd传递闭包+输出连通分量)

    电话圈 紫书P365 [题目链接]电话圈 [题目类型]Floyd传递闭包+输出连通分量 &题解: 原来floyd还可以这么用,再配合连通分量,简直牛逼. 我发现其实求联通分量也不难,就是for ...

随机推荐

  1. 原生的强大DOM选择器querySelector - querySelector和querySelectorAll

    在传统的 JavaScript 开发中,查找 DOM 往往是开发人员遇到的第一个头疼的问题,原生的 JavaScript 所提供的 DOM 选择方法并不多,仅仅局限于通过 tag, name, id ...

  2. PHPExcel 基本用法详解

    .header header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: ...

  3. sdut2613(This is an A+B Problem)大数加法(乘法)

    #include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>u ...

  4. HTML <input> 标签的 name 属性

    定义和用法 name 属性规定 input 元素的名称. name 属性用于对提交到服务器后的表单数据进行标识,或者在客户端通过 JavaScript 引用表单数据. 注释:只有设置了 name 属性 ...

  5. [LeetCode] 67. Add Binary_Easy tag: String

    Given two binary strings, return their sum (also a binary string). The input strings are both non-em ...

  6. 梯度消失与梯度爆炸 ==> 如何选择随机初始权重

    梯度消失与梯度爆炸 当训练神经网络时,导数或坡度有时会变得非常大或非常小,甚至以指数方式变小,这加大了训练的难度 这里忽略了常数项b.为了让z不会过大或者过小,思路是让w与n有关,且n越大,w应该越小 ...

  7. Java接口多线程并发测试 (一)

    本文为作者原创,禁止转载,违者必究法律责任!!! 本文为作者原创,禁止转载,违者必究法律责任!!! Java接口多线程并发测试 一,首先写一个接口post 请求代码: import org.apach ...

  8. Java编写验证码

    Java后台代码(CheckCodeServlet.java) package web; import java.awt.Color; import java.awt.Font; import jav ...

  9. Leetcode: Longest Consecutive Sequence && Summary: Iterator用法以及ConcurrentModificationException错误说明

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  10. 使用 MtVerify.h头文件 ,用的时候把他头文件的内容添加到项目

    #include <windows.h>  //windodws变量相关头文件 MtVerify.h的内容如下:#pragma comment( lib, "USER32&quo ...