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 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

2014上海全国邀请赛——题目重现(感谢上海大学提供题目)

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 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 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

2014上海全国邀请赛——题目重现(感谢上海大学提供题目)

Recommend

hujie   |   We have carefully selected several similar problems for you:  5379 5378 5377 5376 5375

版权声明:本文为博主原创文章,转载请注明出处。

时间: 2024-08-27 20:56:49

HDOJ Page Rank 5097【2014上海邀请赛H题-简单矩阵】的相关文章

BNUOJ 34985 Elegant String 2014北京邀请赛E题 动态规划 矩阵快速幂

Elegant String Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld      Java class name: Main We define a kind of strings as elegant string: among all the substrings of an elegant string, none of them is a permutation of "0, 1,-, k

ACM-ICPC 2014北京邀请赛 H Happy Reverse [模拟]

题意:给出n个二进制串,可以把其中的一些0和1反转(即0变1,1变0),找出转化后n个串中的最大值和最小值的差值. 分析:思路就是把所有的串和反转的存在一个数组中,然后排序,找最大值和最小值的差,(如果是同一个串反转的就找第二大的和最小的或第二小和最大的中的最大值).注意假如只有一个串的话结果为0 DEBUG: 这题写了好久 1.第一次用vim,很爽,但是还没熟练 2.忽视了这题的范围,显然要用longlong 3.用了longlong后还WA,用脚本跑出来数据发现在longlong下,min的

2014 BNU 邀请赛E题(递推+矩阵快速幂)

Elegant String 题意:给定一个字符串,由0-k数字组成,要求该串中,子串不包含0-k全排列的方案数 思路:dp[i][j]表示放到i个数字,后面有j个不相同,然后想递推式,大概就是对应每种情况k分别能由那几种状态转移过来,在纸上画画就能构造出矩阵了,由于n很大,所以用快速幂解决 代码: #include <stdio.h> #include <string.h> const long long MOD = 20140518; int t; long long n; i

2014北京邀请赛E题-矩阵快速幂

题意:长度为n(1<=n<=10^18)的并且任意连续子串都不是0-k(1<=k<=9)的一个排列的字符串有多少种. 解法:矩阵快速幂.dp[i][j]表示i长度最后连续j个不同(即最后j个无重复,最后j+1个有重复)的字符串的个数.状态选好很重要.设计状态时最重要考虑是唯一性和可传递性,比赛时明明知道肯定是矩阵快速幂,但是一直没想到这个状态表示,自己设计的自己都不会转移. dp[i][j]有了后,后边加一个字符,这个字符可以是j之内的任意一个,也可以是j以外的,这样枚举每种情况,

2014 BNU 邀请赛A题(构造问题)

A Matrix 题意:按照题目中给定的方法,给你一个矩阵,求出变换出该矩阵的字符串 思路:构造问题,在纸上多画几组就能发现,每次必须从上往下找到一条路径,最后输出这些路径,按照开头最大的最晚输出,找的过程中只要不断往下一层找一个大的即可,并且如果一开使有一行是非递增就是错误 代码: #include <stdio.h> #include <string.h> #include <vector> #include <map> using namespace

2014 BNU 邀请赛B题(枚举)

Beautiful Garden 题意:x轴上放了一些树,现在要移动一些树使得所有树都等间距,问最少要移动多少棵 思路:枚举,枚举第一棵树,和另一棵树,以及中间有多少树,这样就能知道等差数列的首项和公差,然后再循环一边计算出答案,保存最小值 代码: #include <stdio.h> #include <string.h> #include <algorithm> #include <math.h> using namespace std; #define

2014 BNU邀请赛F题(枚举)

Football on Table 题意:一些杆上有人,人有一个宽度,然后现在有一个球射过去,要求出球不会碰到任何人的概率 思路:计算出每根杆的概率,之后累乘,计算杆的概率的时候,可以先把每块人的区间长度再移动过程中会覆盖多少长度累加出来,然后(1?总和/可移动距离)就是不会碰到的概率 代码: #include <stdio.h> #include <string.h> #include <math.h> const double eps = 1e-8; int t,

BNUOJ 34985 Elegant String 2014北京邀请赛E题 矩阵快速幂

题目链接:http://acm.bnu.edu.cn/bnuoj/problem_show.php?pid=34985 题目大意:问n长度的串用0~k的数字去填,有多少个串保证任意子串中不包含0~k的某一个全排列 邀请赛上A的较多的一道题,比赛的时候死活想不出,回来之后突然就想通了,简直..... = =! 解题思路: 对于所有串我们都只考虑末尾最多有多少位能构成全排列的一部分(用l来表示),即最多有多少位不重复的数字出现,将问题转化为求末尾最多有k位能构成全排列的串的总数量 假设k为5,有一个

HDU 5093Battle ships(2014上海邀请赛)

题目: Battle ships Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 477    Accepted Submission(s): 197 Problem Description Dear contestant, now you are an excellent navy commander, who is responsi