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 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 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 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 Recommend hujie | We have carefully selected several similar problems for you: 5379 5378 5377 5376 5375 |
****这题只有题意才是最难的******
好好翻译下题目:
给你一个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; }
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 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 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 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 Recommend hujie | We have carefully selected several similar problems for you: 5379 5378 5377 5376 5375 |
版权声明:本文为博主原创文章,转载请注明出处。