Page RankTime 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 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 q cur and q next 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 E ij (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
Sample Output
Source
Recommend
|
****这题只有题意才是最难的******
好好翻译下题目:
给你一个N*N的矩阵,先判断每一行的1的总个数cnt,然后如果mat[ i ] [ j ] =1,那么mat[ j ] [ i ]= 1 / cnt。然后经过上述得到的S矩阵,然后经过给定的第一个公式变化,得到G矩阵,然后给你一个向量qc(向量初值没说,不过坐标好像全是1),用给定的qc这个向量乘以G矩阵得到结果向量qn,如果qc与qn的向量的距离<eps 就跳出循环。然后结果向量变成当前向量,再用当前向量去乘G矩阵,就这样一直循环,直到跳出循环。输出结果向量~~~。
bool 函数默认返回true。 忘加return false~结果测试数据一直不对~。
AC代码:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#define MAXN 3000+3
const double eps=1e-10;
using namespace std;
int N;
double mat[MAXN][MAXN];
char a[MAXN];
double qn[MAXN],qc[MAXN];
bool dist(double X[],double Y[])
{
double dis=0.0;
for(int i=0;i<N;i++) dis+=((X[i]-Y[i])*(X[i]-Y[i]));
if(sqrt(dis)<eps) return true;
return false;
}
int main()
{
while(scanf("%d",&N)!=EOF){
int cnt;
double C=(1.0-0.85)/N;
for(int i=0;i<N;i++){
scanf("%s",a);
cnt=0;
for(int j=0;j<N;j++)
if(a[j]=='1')cnt++;
for(int j=0;j<N;j++){
if(a[j]=='1') mat[j][i]=1.0/cnt;
else mat[j][i]=0.0;
mat[j][i]=mat[j][i]*0.85+C;
}
qc[i]=1.0;
qn[i]=0.0;
}
while(1){
if(dist(qc,qn)) break;
for(int i=0;i<N;i++){
qn[i]=0.0;
for(int j=0;j<N;j++)
qn[i]+=qc[j]*mat[i][j];
}
for(int i=0;i<N;i++)
swap(qn[i],qc[i]);
}
for(int i=0;i<N;i++){
printf("%.2lf",qc[i]);
if(i<N-1) printf(" ");
}
printf("\n");
}
return 0;
}