Hdoj page Rank 5097 "2014 Shanghai Invitational Q-Simple matrix"

Source: Internet
Author: User



Page RankTime limit:3000/1500 MS (java/others) Memory limit:100000/100000 K (java/others)
Total submission (s): 282 Accepted Submission (s): 77


Problem Descriptionevaluation and rank of Web pages are 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, s Uch as the world Wide Web, with the purpose of "measuring" its relative importance within the set. The algorithm is applied to any collection of entities with reciprocal quotations and references. The numerical weight that it assigns to any given element E was 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 are defined as Q = Gq, Where, S is the Destination-by-source stochastic Matrix, you are all one matrix, n are the number of nodes andαis the weight between 0 and 1 (here we use 0.85).

For the example in the right, we have:



Denote the current PageRank vector and the next PageRank vectors 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).
Inputthe input contains many test cases.

For each case, there is 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 have a hyper link to the j-th page.
Outputoutput one line with the eigenvector. The numbers should is separated by a space and is correctly rounded to the decimal places.
Sample Input
40111001100010100

Sample Output
0.15 1.49 0.83 1.53

SOURCE2014 Shanghai National Invitational Competition--re-title (thanks to Shanghai University for its topics)
Recommendhujie | We have carefully selected several similar problems for you:5379 5378 5377 5376 5375

This problem is only test instructions is the hardest ******

A good translation of the following topics:

Give you a n*n matrix, first determine the total number of 1 per row of CNT, and then if mat[i] [j] = 1, then mat[j] [i]= 1/cnt. Then through the resulting s matrix, and then after the given first formula changes, get the G matrix, and then give you a vector QC (vector initial value did not say, but the coordinates seem to be all 1), with a given QC this vector multiplied by the G matrix to get the result vector qn, if the QC and qn vector distance <eps Just jump out of the loop. Then the result vector becomes the current vector, then uses the current vector to multiply the G-matrix, so it loops until it jumps out of the loop. Output result vector ~ ~ ~.

The BOOL function returns true by default. Forgot to add return false~ results The test data has been wrong ~.

AC Code:

#include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include < algorithm> #define MAXN 3000+3const 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 Descriptionevaluation and rank of Web pages are 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, s Uch as the world Wide Web, with the purpose of "measuring" its relative importance within the set. The algorithm is applied to any collection of entities with reciprocal quotations and references. The numerical weight that it assigns to any given element E was 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 are defined as Q = Gq, Where, S is the Destination-by-source stochastic Matrix, you are all one matrix, n are the number of nodes andαis the weight between 0 and 1 (here we use 0.85).

For the example in the right, we have:



Denote the current PageRank vector and the next PageRank vectors 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).
Inputthe input contains many test cases.

For each case, there is 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 have a hyper link to the j-th page.
Outputoutput one line with the eigenvector. The numbers should is separated by a space and is correctly rounded to the decimal places.
Sample Input
40111001100010100

Sample Output
0.15 1.49 0.83 1.53

SOURCE2014 Shanghai National Invitational Competition--re-title (thanks to Shanghai University for its topics)
Recommendhujie | We have carefully selected several similar problems for you:5379 5378 5377 5376 5375

Copyright NOTICE: This article is the original blogger articles, reproduced please indicate the source.

Hdoj page Rank 5097 "2014 Shanghai Invitational Q-Simple matrix"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.