HDU 5097 Page Rank(矩阵模拟)——2014上海全国邀请赛——题目重现(感谢上海大学提供题目)
2016-10-12 20:16
471 查看
传送门
Total Submission(s): 346 Accepted Submission(s): 105
[align=left]Problem Description[/align] 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).
[align=left]Input[/align] 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.
[align=left]Output[/align] Output one line with the eigenvector. The numbers should be separated by a space and be correctly rounded to two decimal places.
[align=left]Sample Input[/align]
题目大意:
说实话,这个题目最难的应该是题意了把,这个题目读了很多次都没有读懂,首先读一下题目大意,然后大体了解一下背景,主要是那个公式:然后,我说一下公式的每隔变量都代表啥: G =α∗S+(1−α)∗1n∗U,其中 α 是一个常数 等于 0.85,然后 S 是一个 n∗n 的矩阵,怎么算的呢,首先题目输入中给了我们一个 n∗n 的01矩阵,然后我们通过这个矩阵来构造出 S 来,首先将输入的矩阵中每一行的 1 的个数 cnt 求出来,然后在 S 中就是 1/cnt ,然后将行列转置,输入矩阵 1 对应的行和列,就是 S 矩阵中对应的列和行,然后值就是 1/cnt,限制再来说一下 n ,n是输入的时候给定的, U 是一个全是 1 的矩阵,当时我是怎么都没读出来这个意思 U is all one matrix 我理解的就是 这个是一个矩阵,唉,这英语水平绝了,我们知道了这个之后就是让我们求一个特征向量,然后满足 qnext=G∗qcur 最后当这个 q 收敛了就不用算了。
解题思路:
其实读懂了题目就很简单了,关键是题目的意思,就是按照题目的意思进行模拟就行了,处理到 qnext−qcur<eps就行了(其实也可以就是循环 ≥20 次就行了)。
My Code:
Page Rank
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Others)Total Submission(s): 346 Accepted Submission(s): 105
[align=left]Problem Description[/align] 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).
[align=left]Input[/align] 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.
[align=left]Output[/align] Output one line with the eigenvector. The numbers should be separated by a space and be correctly rounded to two decimal places.
[align=left]Sample Input[/align]
4 0111 0011 0001 0100
题目大意:
说实话,这个题目最难的应该是题意了把,这个题目读了很多次都没有读懂,首先读一下题目大意,然后大体了解一下背景,主要是那个公式:然后,我说一下公式的每隔变量都代表啥: G =α∗S+(1−α)∗1n∗U,其中 α 是一个常数 等于 0.85,然后 S 是一个 n∗n 的矩阵,怎么算的呢,首先题目输入中给了我们一个 n∗n 的01矩阵,然后我们通过这个矩阵来构造出 S 来,首先将输入的矩阵中每一行的 1 的个数 cnt 求出来,然后在 S 中就是 1/cnt ,然后将行列转置,输入矩阵 1 对应的行和列,就是 S 矩阵中对应的列和行,然后值就是 1/cnt,限制再来说一下 n ,n是输入的时候给定的, U 是一个全是 1 的矩阵,当时我是怎么都没读出来这个意思 U is all one matrix 我理解的就是 这个是一个矩阵,唉,这英语水平绝了,我们知道了这个之后就是让我们求一个特征向量,然后满足 qnext=G∗qcur 最后当这个 q 收敛了就不用算了。
解题思路:
其实读懂了题目就很简单了,关键是题目的意思,就是按照题目的意思进行模拟就行了,处理到 qnext−qcur<eps就行了(其实也可以就是循环 ≥20 次就行了)。
My Code:
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> using namespace std; const int MAXN = 3e3+5; const double eps = 1e-10; double a[MAXN][MAXN]; char str[MAXN][MAXN]; int n; bool Judge(double qcur[], double qnext[]){ double sum = 0; for(int i=0; i<n; i++) sum += fabs(qcur[i]-qnext[i]); if(sum < eps) return 0; return 1; } double qcur[MAXN], qnext[MAXN]; int main() { while(~scanf("%d",&n)){ for(int i=0; i<n; i++) scanf("%s",str[i]); memset(a, 0, sizeof(a)); memset(qcur, 0, sizeof(qcur)); memset(qnext, 0, sizeof(qnext)); double tmp = 0.85;///阿尔法 for(int i=0; i<n; i++){ double cnt = 0; for(int j=0; j<n; j++) if(str[i][j] == '1') cnt++; for(int j=0; j<n; j++) if(str[i][j] == '1') a[j][i] = tmp/cnt; } for(int i=0; i<n; i++) for(int j=0; j<n; j++) a[i][j] += 0.15/n; for(int i=0; i<n; i++) for(int j=0; j<n; j++) qcur[i] += a[i][j]; for(int i=0; i<n; i++) for(int j=0; j<n; j++) qnext[i] += qcur[j] * a[i][j]; while(Judge(qcur, qnext)){ for(int i=0; i<n; i++) qcur[i] = qnext[i]; memset(qnext, 0, sizeof(qnext)); for(int i=0; i<n; i++) for(int j=0; j<n; j++) qnext[i] += qcur[j] * a[i][j]; } for(int i=0; i<n-1; i++) printf("%.2f ",qcur[i]); printf("%.2f\n",qcur[n-1]); } return 0; }
相关文章推荐
- 【HDU】2014上海全国邀请赛——题目重现(感谢上海大学提供题目) 题解
- hdu 5090 Game with Pearls 2014上海全国邀请赛——题目重现
- hdu 5092 Seam Carving 2014上海全国邀请赛——题目重现
- 2014西安全国邀请赛——题目重现(感谢西工大+复旦)HDOJ4847 Wow! Such Doge!
- 2014西安全国邀请赛——题目重现(感谢西工大+复旦 HDOJ 4849 Wow! Such City!
- 2014上海全国邀请赛——题目重现 4.24
- HDU5092 Seam Carving(2014上海全国邀请赛——题目重现)(DP)
- HDU5099——Comparison of Android versions(简单题)(2014上海邀请赛重现)
- HDU_2013 ACM-ICPC南京赛区全国邀请赛——题目重现
- 2014上海全国邀请赛1003(hdu 5092)
- hdu 4584 building-bridge 暴力的题,怎么暴力怎么干。。2013 ACM-ICPC杭州赛区全国邀请赛——题目重现
- hdu 4585 Shaolin 2013 ACM-ICPC杭州赛区全国邀请赛——题目重现
- 2014上海全国邀请赛(hdu 5090 - 5099)dp+线段树+拓扑排序+bfs(状态压缩)
- hdu 4585 Shaolin 2013 ACM-ICPC杭州赛区全国邀请赛——题目重现
- HDU5092——Seam Carving(动态规划+回溯)(2014上海邀请赛重现)
- HDOJ 题目5097 Page Rank(矩阵运算,模拟)
- 2014上海全国邀请赛1001(hdu 5090)
- 2014上海全国邀请赛1006(hdu 5095)
- HDU 5097 Page Rank(模拟,矩阵运算)
- HDU5093——Battle ships(最大二分匹配)(2014上海邀请赛重现)