HDOJ 题目5097 Page Rank(矩阵运算,模拟)

Page Rank

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others)

Total Submission(s): 280    Accepted Submission(s): 75

Problem Description

Evaluation and rank of web pages is a hot topic for many internet companies and researchers. PageRank is a link analysis tool and it assigns a numerical weighting to each element of a hyperlinked set of documents, such as the World Wide Web, with the purpose
of "measuring" its relative importance within the set. The algorithm may be applied to any collection of entities with reciprocal quotations and references. The numerical weight that it assigns to any given element E is referred to as the PageRank of E and
denoted by . Other factors like Author Rank can contribute to the importance of an entity.

For simplicity, in this problem PageRank vector q is defined as q = Gq, Where , S is the destination-by-source stochastic matrix, U is all one matrix, n is the number of
nodes and α is the weight between 0 and 1 (here we use 0.85).

For the example on the right, we have:

Denote the current PageRank vector and the next PageRank vector by qcur and qnext respectively. The process is to compute the iterative powering for finding the first eigenvector.

The computation ends until  for some small ε(10-10).

Input

The input contains many test cases.

For each case, there are multiple lines. The first line contains an integer N(N<=3000), which represents the number of pages. Then a N*N zero-one matrix follows. The element Eij (0 <= i, j < N) on the matrix represents whether the i-th page has a
hyper link to the j-th page.

Output

Output one line with the eigenvector. The numbers should be separated by a space and be correctly rounded to two decimal places.

Sample Input

4
0111
0011
0001
0100

Sample Output

0.15 1.49 0.83 1.53

Source

field=problem&key=2014%C9%CF%BA%A3%C8%AB%B9%FA%D1%FB%C7%EB%C8%FC%A1%AA%A1%AA%CC%E2%C4%BF%D6%D8%CF%D6%A3%A8%B8%D0%D0%BB%C9%CF%BA%A3%B4%F3%D1%A7%CC%E1%B9%A9%CC%E2%C4%BF%A3%A9&source=1&searchmode=source" style="color:rgb(26,92,200); text-decoration:none">2014上海全国邀请赛——题目重现(感谢上海大学提供题目)

Recommend

hujie   |   We have carefully selected several similar problems for you:  

pid=5379" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5379 

pid=5378" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5378 

pid=5377" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5377 

pid=5376" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5376 

pid=5375" target="_blank" style="color:rgb(26,92,200); text-decoration:none">5375

模拟,,,

add函数没有卵用。。

ac代码

Problem : 5097 ( Page Rank )     Judge Status : Accepted
RunId : 14492913    Language : C++    Author : lwj1994
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta
#include<stdio.h>
#include<string.h>
#include<math.h>
#define eps 1e-10
char map[3030];
double ans[3030][3030];
double q[2][3030];
int n;
void muti(double a[][3030],double num)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            a[i][j]*=num;
    }
}
void add(double a[][3030],double b[][3030])
{
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            a[i][j]+=b[i][j];
    }
}
int jud()
{
    double ans=0;
    int i;
    for(i=0;i<n;i++)
    {
        ans+=(q[0][i]-q[1][i])*(q[0][i]-q[1][i]);
    }
    //ans=sqrt(ans);
    if(fabs(ans)<eps)
        return 1;
    return 0;
}
int main()
{
    //int n;
    while(scanf("%d",&n)!=EOF)
    {
        int i,j;
        double a=0.85;
        memset(ans,0,sizeof(ans));
        for(i=0;i<n;i++)
        {
            int sum=0;
            scanf("%s",&map);
            for(j=0;j<n;j++)
            {
                if(map[j]=='1')
                    sum++;
                //U[i][j]=1;
            }
            for(j=0;j<n;j++)
            {
                if(map[j]=='1')
                    ans[j][i]=1.0/sum;
            }
        }
        muti(ans,a);
    //    muti(U,1.0/n*(0.15));
    //    printf("\n");
    //    add(ans,U);
        for(i=0;i<n;i++)
            for(j=0;j<n;j++)
                ans[i][j]+=(0.15/n);
        int p=0;
        for(i=0;i<n;i++)
        {
            q[p][i]=1;
            q[p^1][i]=0;
        }
        //mmuti(q[p],ans,q[p^1]);
        //p^=1;
        while(!jud())
        {
            //q[p^1]=mmuti(q[p],ans);
            for(i=0;i<n;i++)
            {
                q[p^1][i]=0;
                for(j=0;j<n;j++)
                    q[p^1][i]+=q[p][j]*ans[i][j];
            }
            p^=1;
        }
        printf("%.2lf",q[p][0]);
        for(i=1;i<n;i++)
        {
            printf(" %.2lf",q[p][i]);
        }
        printf("\n");
    }
}

时间: 2024-10-25 22:09:30

HDOJ 题目5097 Page Rank(矩阵运算,模拟)的相关文章

HDU 5097 Page Rank

题意有点难读,给一个矩阵,Eij = 1表示i到j有个超连接,假设都是随机的,求S矩阵,S的j行和i列表示从i到j的概率.然后求出那个矩阵,模拟乘一下. 似乎任意的q都会收敛. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> const double eps = 1e-10; const int N = 3000+10; double G[N][N]; const

HDOJ 题目1035 Robot Motion(模拟)

Robot Motion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7372    Accepted Submission(s): 3389 Problem Description A robot has been programmed to follow the instructions in its path. Instruc

HDOJ Page Rank 5097【2014上海邀请赛H题-简单矩阵】

Page Rank Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Others) Total Submission(s): 282    Accepted Submission(s): 77 Problem Description Evaluation and rank of web pages is a hot topic for many internet companies and

HDOJ题目3729 I&#39;m Telling the Truth(二分图)

I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1629    Accepted Submission(s): 805 Problem Description After this year's college-entrance exam, the teacher did a survey i

HDOJ 题目分类

HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:    用STL中的next_permutation()1029:1032:1037:1039:1040:1056:1064:1065:1076:    闰年 1084:1085:1089,1090,1091,1092,1093,1094, 1095, 1096:全是A+B1108:1157:1196:1

HLG 1752 Page Rank (线段树)

链接: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=1752 Description There are n webpages, each of which has its respective page rank. The content is constantly updated and page rank is also constantly changing. Can you im

[IR课程笔记]Page Rank

主要目的: 在网络信息检索中,对每个文档的重要性作出评价. Basic Idea: 如果有许多网页链接到某一个网页,那么这个网页比较重要. 如果某个网页被一个权重较大的网页链接,那么这个网页比较重要. 随机游走模型: 过程:1.在所有网页中,随机选择一个网页作为游走的开端. 2.然后在当前网页上的超链接中,随机选择一个超链接跳转到下一个网页. 3.大量重复1.2的过程. 重要度计算方法: Pr(pi|p1)表示从编号为1的网页跳转到编号为i的网页的概率,其计算方式为 Pr(Pi|P1) = 1/

HDOJ 题目3966 Aragorn&#39;s Story(Link Cut Tree成段加减点权,查询点权)

Aragorn's Story Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5505    Accepted Submission(s): 1441 Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lor

HDOJ 题目4738 Caocao&#39;s Bridges(双联通,求桥)

Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1752    Accepted Submission(s): 642 Problem Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. B