zoukankan      html  css  js  c++  java
  • UVa 821 Page Hopping

    题意:

      给出一个有向图,求所有路径(两点间的最短路径)的平均值。

    分析:

      用floyd求两点间的最短距离,然后求平均就好。

    代码:

      

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    using namespace std;
    int dist[101][101];
    int maxn=100000001;
    int main()
    {
    int a,b,n,cas=1;
    while(~scanf("%d%d",&a,&b)&&a+b)
    {
    int i,j,k;
    for(i=0;i<101;i++)
    for(j=0;j<101;j++)
    dist[i][j]=maxn;
    for(i=0;i<101;i++)
    dist[i][i]=0;
    n=0;
    dist[a][b]=1;
    if(a>n)
    n=a;
    if(b>n)
    n=b;
    while(~scanf("%d%d",&a,&b)&&a+b)
    {
    dist[a][b]=1;
    if(a>n)
    n=a;
    if(b>n)
    n=b;
    }
    for(k=1;k<=n;k++)
    {
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    if(dist[i][j]>dist[i][k]+dist[k][j])
    dist[i][j]=dist[i][k]+dist[k][j];
    }
    }
    }
    int count=0,sum=0;
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=n;j++)
    {
    if(dist[i][j]<maxn&&dist[i][j])
    {
    sum+=dist[i][j];
    count++;
    }
    }
    }
    //cout<<sum<<endl;
    printf("Case %d: ",cas++);
    printf("average length between pages = %.3lf clicks ",1.0*sum/count);
    }
    }
  • 相关阅读:
    阿里巴巴excel工具easyexcel 助你快速简单避免OOM
    IoC和AOP的理解
    WebSocket和kafka实现数据实时推送到前端
    Swagger使用指南
    转载:对于马老师对996的看法
    基础:新建个maven项目
    eclipse集成lombok
    多线程
    jar包

  • 原文地址:https://www.cnblogs.com/137033036-wjl/p/4909000.html
Copyright © 2011-2022 走看看