Page Hopping

【Uva 821】Page Hopping 翻译+题解 It was recently reported that, on the average, only 19 clicks are necessary to move from any page on the World Wide Web to any other page. That is, if the pages on the web are viewed as nodes in a 阅读详情

It was recently reported that, on the average, only 19 clicks are necessary to move from any page on
the World Wide Web to any other page. That is, if the pages on the web are viewed as nodes in a
graph, then the average path length between arbitrary pairs of nodes in the graph is 19.
Given a graph in which all nodes can be
reached from any starting point, your job is to
find the average shortest path length between arbitrary
pairs of nodes. For example, consider the
following graph. Note that links are shown as directed
edges, since a link from page a to page b
does not imply a link from page b to page a.
The length of the shortest path from node 1
to nodes 2, 3, and 4 is 1,1, and 2 respectively. From node 2 to nodes 1, 3 and 4, the shortest paths
have lengths of 3, 2, and 1. From node 3 to nodes 1, 2, and 4, the shortest paths have lengths of 1, 2,
and 3. Finally, from node 4 to nodes 1, 2, and 3 the shortest paths have lengths of 2, 3, and 1. The
sum of these path lengths is 1 + 1 + 2 + 3 + 2 + 1 + 1 + 2 + 3 + 2 + 3 + 1 = 22. Since there are
12 possible pairs of nodes to consider, we obtain an average path length of 22/12, or 1.833 (accurate
to three fractional digits).
Input
The input data will contain multiple test cases. Each test case will consist of an arbitrary number of
pairs of integers, a and b, each representing a link from a page numbered a to a page numbered b. Page
numbers will always be in the range 1 to 100. The input for each test case will be terminated with a
pair of zeroes, which are not to be treated as page numbers. An additional pair of zeroes will follow
the last test case, effectively representing a test case with no links, which is not to be processed. The
graph will not include self-referential links (that is, there will be no direct link from a node to itself),
and at least one path will exist from each node in the graph to every other node in the graph.
Output
For each test case, determine the average shortest path length between every pair of nodes, accurate to
three fractional digits. Display this length and the test case identifier (theyre numbered sequentially
starting with 1) in a form similar to that shown in the sample output below.
Sample Input
1 2 2 4 1 3 3 1 4 3 0 0
1 2 1 4 4 2 2 7 7 1 0 0
0 0
Sample Output
Case 1: average length between pages = 1.833 clicks
Case 2: average length between pages = 1.750 clicks
网页之间会有联通,求平均任意两个网页到达需要的次数,直接把两个网页能到达的找出来,然后累和,再除以总的网页,根据每个网页这个特性,可以使用弗洛伊德,三重暴力……然而我作死用了迪杰斯特拉恶心版

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int a[105][105], d[105][105], leap[105];
int main()
{
    int i, j, m, n, ans, t, x, y, num, p = 1;
    while (scanf("%d%d", &x, &y) != EOF)
    {
        if (!x&&!y)break;
        for (i = 1; i <= 100;i++)
        for (j = 1; j <= 100; j++)
        {
            a[i][j] = d[i][j] = inf;
        }
        memset(leap, 0, sizeof(leap));
        leap[x] = leap[y] = 1;
        num = 2;
        a[x][y] = 1;
        while(scanf("%d%d", &x, &y) != EOF)
        {
            if (!x&&!y)break;
            if (!leap[x])num++;
            leap[x] = 1;
            if (!leap[y])num++;
            leap[y] = 1;
            a[x][y] = 1;
        }
        for (i = 1; i <= 100;i++)
        for (j = 1; j <= 100; j++)
            d[i][j] = a[i][j];
        for (i = 1; i <= 100; i++)
        {
            memset(leap, 0, sizeof(leap));
            leap[i] = 1;
            int k;
            for (k = 1; k <= 100; k++)
            {
                int temp, x;
                temp = x = inf;
                for (j = 1; j <= 100; j++)
                {
                    if (!leap[j] && d[i][j] <= temp)
                    {
                        temp = d[i][j];
                        x = j;
                    }
                }
                if (temp == inf)break;
                leap[x] = 1;
                for (j = 1; j <= 100; j++)
                {
                    d[i][j] = min(d[i][j], d[i][x] + a[x][j]);
                }
            }
        }
        ans = 0;
        int ans1;
        double ans2;
        for (i = 1; i <= 100;i++)
        for (j = 1; j <= 100;j++)
        if (d[i][j] != inf&&i != j)
            ans = ans + d[i][j];
        ans1 = num*(num - 1);
        ans2 = ans*1.0 / ans1;
        cout << "Case " << p << ": average length between pages = ";
        p++;
        printf("%.3lf", ans2);
        cout << " clicks" << endl;
    }
    return 0;
}
车企常用架构、通信设计、需求管理工具全汇总 车辆技术是个系统工程,比较大,需要多人协作。“协作”往往需要工具参与,才能保证协作过程的高效、有条不紊。 【文章系转载,出处见图片水印】 今天我们就来捋一捋汽车行业常用的架构、网络开发工具~ Preevision 大名鼎鼎的Preevision,来自大名鼎鼎的Vector。 个人觉得,它是Vector公司最牛逼、最神秘、最高高在上的产品,犹如空谷回响、千里传音,但是很少看到它真正落地。 它最引以为傲的,或许是在给客户做介绍的时候,说“我们甚至能够精确到每一根线束的长度”,但是反观. 阅读详情

相关推荐

Aix升级和安装ssh配置过程

Aix升级和安装ssh配置过程Aix升级和安装ssh配置过程配置前背景配置步骤 Aix升级和安装ssh配置过程 部门IBM小型机的Aix操作系统需要进行ssh补丁修复,修复其实就是ssh版本你的升级,对升级的过程和中途遇到的问题做了记录如下。 配置前背景 操作系统: gdboss2/>uname -u //操作系统的Aix5.3 IBM,020693E5P gdboss2/&gt...

阿阿阿唱的博客 2990

Page Hopping UVA - 821(floyd)

Page Hopping UVA - 821 题意:(lrj老师的翻译) 最近的研究表明,互联网上任何一个网页在平均情况下,最多只需要单机19次就能到达任意一个其他网页。如果把网页看成一个有向图的结点,则该图中任意两点间的最短距离的平均值是19. 求: 输入一个n个点的有向图。(任意结点a∈[1,100]\in[1,100]∈[1,100])。数据保证任意两个点之间可以相互到达。求图中任意两点间的最短距离的平均值 思路: 首先可以发现数据小,又是求最短路,可以考虑floyd 观察sample_te

qq_45377553的博客 161

基于FMCW技术的毫米波雷达测速原理与应用

调频连续波(FMCW)技术是毫米波雷达中实现高精度测速的核心方法之一。本文详细介绍了FMCW测速的基本原理、信号处理流程以及在实际应用中的关键技术。通过分析FMCW雷达的多普勒效应和频率差测量方法,本文展示了如何利用FMCW技术实现目标速度的高精度检测。此外,本文还探讨了FMCW测速在自动驾驶、智能交通和工业自动化等领域的应用案例,为毫米波雷达开发者提供了理论支持和实践指导。

不谈枯燥公式,只聊雷达趋势。用大白话解读毫米波里的黑科技。 1136

Page Hopping UVA - 821(floyd)

传送门 题意:研究证明,互联网上任何一个网页在平均情况下最多只需要单击19次就可以到达任意一个网页。如果把网页看成一个有向图中的结点,则该图中任意两点间最短距离的平均值为19。现在输入一个n个点的有向图,假定任意两个点之间都能互相到达,求任意两点最短距离的平均值。 题解:直接使用floyd,注意题中点出现不连续,属于WF的签到题吧 附上代码: #include&lt;bits/stdc...

肘子的博客 260

新手必看!Cisco Packet Tracer 8.2从安装到完成第一个局域网实验(附常见问题解决)

本文为网络新手提供了Cisco Packet Tracer 8.2的完整入门指南。从官方下载安装、界面熟悉,到核心的拖拽设备、连线、配置IP地址三步操作,手把手教你完成第一个局域网组网实验。文章重点讲解了如何通过Ping命令验证连通性,并附带了连线错误、IP配置不当等常见问题的解决思路,帮助初学者快速上手这款强大的思科模拟器。

android的专栏 866

团结引擎+OpenHarmony 2实战篇:从零构建鸿蒙应用开发环境

本文详细介绍了如何从零开始构建鸿蒙应用开发环境,重点讲解了团结引擎与OpenHarmony 2的实战配置步骤。内容包括DevEco Studio安装、OpenHarmony SDK配置、团结引擎集成及项目创建等关键环节,帮助开发者快速搭建高效的开发环境,提升鸿蒙应用开发效率。

weixin_29294395的博客 262

UVA 821 Page Hopping——最短路

#include &lt;cstdio&gt; #include &lt;cstring&gt; #include &lt;iostream&gt; #include &lt;algorithm&gt; using namespace std; const int maxn = 105; const int INF = 0X3f3f3f3f; int kase = 0; int cnt, dp[m...

hao_zong_yin的博客 390

别再算错了!深入SAP FI后台,看懂外币清账时汇兑损益的自动计算逻辑

刚接手一家跨国企业的SAP财务模块优化项目时,我遇到了一个棘手案例:每月末外币清账产生的汇兑损益金额总是与财务团队的预期存在差异。最令人困惑的是,系统似乎"擅自"计算出了1989.11元的损益,而财务人员反复手工验算都无法复现这个数字。这让我意识到,要真正掌握SAP FI的外币处理能力,必须深入理解系统后台的汇兑损益计算逻辑——不是停留在操作层面,而是穿透到算法内核。这个过程的精妙之处在于,损益金额不是简单比较两个时点的市场汇率,而是反映业务执行全周期的汇率影响。:损益金额与手工计算不符。

weixin_32932149的博客 473

Uva-11248-Frequency Hopping

大白书上面网络流的一道题,

z309241990的专栏 732

基于YOLO26深度学习框架的人脸识别门禁系统的算法研究实现方法

本文研究了基于YOLO26深度学习框架的人脸识别门禁系统实现方法。系统采用YOLO26目标检测算法,通过CSPDarknet53主干网络、特征金字塔结构和注意力机制实现高效人脸检测。研究内容包括数据预处理、模型训练优化和身份验证等关键技术,使用迁移学习策略和CIoU损失函数提升检测精度。该系统可应用于智能安防场景,具有实时性强、识别准确的特点,为门禁管理提供了智能化解决方案。

一键难忘的博客 766

可控异常的契约化设计:在 ABAP 中用 CX_STATIC_CHECK 把可预期错误变成接口的一部分

文章摘要: 本文探讨了ABAP系统中异常处理的工程化设计原则,强调将可预期的业务异常作为接口契约的一部分。核心观点是:对于调用方能够合理处理的错误情况,应使用继承自CX_STATIC_CHECK的受检异常,通过方法签名强制调用方处理或显式转发。文章对比了ABAP三大异常根类的适用场景,提出"三问法"判断异常是否适合受检处理,并给出了包含上下文信息的异常类实现示例。通过Fiori文件上传案例,展示了如何在分层架构中合理传递和转换异常,最终在OData服务层将业务异常映射为标准错误响应。这种

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 3062

Page Hopping UVA - 821

水题来一发. #include &lt;iostream&gt; #include &lt;bits/stdc++.h&gt; #define maxn 105 #define INF 0x3f3f3f3f using namespace std; int d[maxn][maxn]; int n; void init() { memset(d,INF, sizeof(d)); ...

剑似生平 198

052、联发科Imagiq HyperEngine架构适配:天玑9000/9200的ISP多核并行调度与Tuning Toolkit调优案例

摘要: 项目组在适配联发科天玑9200的Imagiq 890 ISP架构时,遇到多摄预览功耗过高、帧率不稳等问题。通过分析多核调度机制,调整辅核QoS通道、优化AI-ISP协同模式(采用FREERUN+运动补偿),并利用Tuning Toolkit的Pipeline Viewer动态分配负载,最终降低功耗30mA、提升画质。关键经验包括:避免多核带宽冲突、合理配置动态时钟策略,以及统一校准参数版本管理。天玑9000/9200的HyperEngine架构需优先理解多核协同逻辑,再针对性调优,否则易引发场景兼容

zzfmlxs的博客 35

UVa 821 - Page Hopping

題目:給你一個有向的地圖,求所有路徑(兩點間的最短路徑)的平均長度。 分析:圖論,最短路。利用floyd求解,然後將所有效的邊加和求平均值即可。 說明:距離700還有14題╮(╯▽╰)╭。 #include #include int dist[101][101]; int oo = 100000001; int main() { int a, b, n, cases = 1; w

小白菜又菜 1555

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Uva 821 - Page Hopping

Floyd类似模板题 100的数据规模很好的样子=.= 算图种两两距离和的平均值 n*(n-1)种 floyd出边数 1Y #include #define INF (int)1e9 int g[110][110]; int should[110]; int max(int a,int b){ if(a>b)return a;return b; } int min(int a,in

On my fighting way 802

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

uva821 Page Hopping( Floyd )

这个点的个数不是最大的编号,而是输入中真实的点的个数 比简单的floyd的题目 代码: #include #include #include using namespace std; const int N = 110; const int INF = 100000000; int g[N][N], a, b, id, sum, n[N], num; int main() {

AClion的专栏 1085

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

821 - Page Hopping (Floyd)

很裸的Floyd水题,只需要注意一点: 题目中给的结点编号并不是完整的从1~n,不过没有关系,因为我们初始化为INF,当两点间距离不等于INF时相加就可以了。 细节参见代码: #include using namespace std; const int maxn = 105; const int INF = 1000000; int a,b,n,d[maxn][maxn],kase = 0

AC_Arthur的专栏 967

【UVA】821-Page Hopping(Floyd)

模板题,求一个点到任何一点的距离,用Floyd就行了,结点不一定是从1 ~ n 的,所以需要记录结点的id 14063895 821 Page Hopping Accepted C++ 0.119 2014-08-19 10:00:27 #include #include #include #include #includ

花月阁 1264

uva 821 Page Hopping 最短路floyd

#include #include using namespace std; const int maxn = 110; const int INF = 1<<20; int d[maxn][maxn],n; void floyd() { for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i!=j&

chen_minghui的博客 422

【floyd算法】UVA821 Page Hopping

Given a graph in which all nodes can be reached from any starting point, your job is to find the average shortest path length between arbitrary pairs of nodes. For example, consider the following grap...

elegant coder 337

UVA Page Hopping(Floyd算法)

题意: 给出若干个点, 求出每对点之间距离的最小平均值。 解题思路: 直接Floyd求出所有点两两之间最短路径累和即可。 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=762 Memory: 0 KB   Tim

MingShen 462

[floyd]UVa821 - Page Hopping

就是一道简单的floyd的题 1A 还是不借助题解独立A题来的酸爽! #include using namespace std; const int INF = 0x3f3f3f3f; int M; int dp[110][110]; bool vis[110]; void floyd(){ for(int k=1;k<=M;k++) for(int i=1;

Dosth_Magic 694

UVA 821 Page Hopping (Floyd)

题意: 告诉你哪两个点连通,求平均距离,为每个结点到其他点距离总和除以总对数。 思路: Floyd水题 这个题点不是连续的,直接存到vector里 枚举vector好了。 #include #include #include #include #define Siz(x) (int)x.size() using namespace std; int g[107][107]; b

aozil_yang的博客 327

UVA821 Page Hopping 解题报告

最近的研究表明,互联网上任何一个网页在平均情况下最多只需要单击19次就能到达任意一个其他网页。如果把网页看成一个有向图中的结点,则该图中任意两点间最短距离的平均值为19。输入一个n(1≤n≤100)个点的有向图,假定任意两点之间都相互到达,求任意两点间最短距离的平均值。建模为边权为1的图,然后就是标准的floyd模板,注意处理一下自环边的问题即可,细节见代码注释。

qq_45554473的博客 418

UVa 821 Page Hopping

题意:   给出一个有向图,求所有路径(两点间的最短路径)的平均值。 分析:   用floyd求两点间的最短距离,然后求平均就好。 代码:    #include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;int...

weixin_34029949的博客 93

UVA 821 Page Hopping

Floyd水题 #include<cstdio> #include<iostream> using namespace std; int N; const int MAXN=1111; int Map[MAXN][MAXN],b[MAXN],path[MAXN][MAXN]; int u[MAXN],v[MAXN]; void init() { ...

weixin_34244102的博客 86
上一篇: Funny Car Racing
下一篇: Say Cheese
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值