• bzoj1491: [NOI2007]社交网络


    题目链接

    bzoj1491: [NOI2007]社交网络

    题解

    n^3枚举一下就没了...

    代码

    #include<cstdio> 
    #include<cstring> 
    #include<algorithm> 
     
    inline int read() { 
         int x = 0,f = 1 ; 
         char c = getchar(); 
         while(c < '0' || c > '9')c = getchar(); 
         while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
         return x * f; 
    } 
    int n,m;
    const int maxn = 1007;  
    int mp[maxn][maxn]; 
    long long cnt[maxn][maxn]; 
    double ans[maxn]; 
    int main() { 
        n = read(),m = read(); 
        memset(mp,0x3f,sizeof mp); 
        for(int a,b,j = 1;j <= m;++ j) { 
            a = read(),b = read(); 
            mp[a][b] = mp[b][a] = read(); 
            cnt[a][b] = cnt[b][a] = 1; 
        } 
         
        for(int k = 1;k <= n;++ k)  
            for(int i = 1;i <= n;++ i)  
                for(int j = 1;j <= n;++ j) { 
                    if(i == k || k == j) continue; 
                    if(mp[i][j] > mp[i][k] + mp[k][j]) { 
                        mp[i][j] = mp[i][k] + mp[k][j]; 
                        cnt[i][j] = cnt[i][k] * cnt[k][j]; 
                    } 
                    else if(mp[i][j] == mp[i][k] + mp[k][j]) 
                        cnt[i][j] += cnt[i][k] * cnt[k][j]; 
                } 
        for(int i = 1;i <= n;++ i) cnt[i][i] = 0 ; 
        for(int x = 1;x <= n;++ x) 
            for(int i = 1;i <= n;++ i) 
                for(int j = 1;j <= n;++ j) 
                    if(mp[i][j] == mp[i][x] + mp[x][j] && cnt[i][j]) 
                        ans[x] += (double )cnt[i][x] * cnt[x][j] / (double) cnt[i][j]; 
        for(int i = 1;i <= n;++ i) printf("%.3lf
    ",ans[i]); 
        return 0; 
    } 
    
  • 相关阅读:
    session
    php增删改查,分页
    sql题
    php简单的数据增删改查
    php简单登录注册验证
    js题
    jQHTML(获取内容和属性)
    jQ效果(动画)
    Codeforces Round #460 (Div. 2): D. Substring(DAG+DP+判环)
    POJ 2891 中国剩余定理(不互素)
  • 原文地址:https://www.cnblogs.com/sssy/p/9526503.html
Copyright © 2020-2023  润新知