SGU196_Matrix Multiplication

给一个无向图,如果第i个点连接第j条边,那么mat[i][j]=1,否则mat[i][j]=0。

求mat的转置乘以本身得到的矩阵每个位置的和是多少?

理解矩阵的意义就比较好做了。

mat[i][j]表示i点可以连接到j边,转置后相乘的意义是第i边和第j边有公共点。

这样,我们只需要统计每个点的度数,这样我们就知道有多少组这样有公共点的边了,也就是最终的答案了。

如果是mat乘以mat的转置,思考的方法也是一样的。

召唤代码君:

#include <iostream>
#include <cstring>
#include <cstdio>
#define maxn 100100
typedef long long ll;
using namespace std;

int d[maxn],n,m,U,V;
ll ans;

int main()
{
    scanf("%d%d",&n,&m);
    ans=m+m;
    while (m--){
        scanf("%d%d",&U,&V);
        d[U]++,d[V]++;
    }
    for (int i=1; i<=n; i++)
        ans+=ll(d[i])*(d[i]-1);
    cout<<ans<<endl;
    return 0;
}

SGU196_Matrix Multiplication

时间: 2024-10-05 03:35:27

SGU196_Matrix Multiplication的相关文章

HDU 1517 A Multiplication Game 博弈

A Multiplication Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6202    Accepted Submission(s): 3532 Problem Description Stan and Ollie play the game of multiplication by multiplying an in

ACDream 1213 Matrix Multiplication (01矩阵处理)

Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description Let us consider undirected graph G = {V; E} which has N vertices and M edges. Incidence matrix of

POJ1651——Multiplication Puzzle

Multiplication Puzzle Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6511   Accepted: 3964 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one

A Multiplication Game

A Multiplication Game http://acm.hdu.edu.cn/showproblem.php?pid=1517 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3761    Accepted Submission(s): 2136 Problem Description Stan and Ollie play

UVAoj 348 - Optimal Array Multiplication Sequence

1 /* 2 题意:矩阵相乘的最少的步数 3 dp[i][j]=min(dp[i][j], dp[i][k]+dp[k+1][j]+num[i-1]*num[k]*num[j]); 4 表示的是第i个矩阵到第j个矩阵相乘的最少步数 5 sign[i][j]表示的是第i个矩阵到第j个矩阵相乘的最少步数是由第i个矩阵到第sign[i][j]个矩阵相乘最少步数 6 和第sign[i][j]+1个矩阵到第j个矩阵相乘最少步数的得到的最小值! 7 */ 8 #include<iostream> 9 #i

Matrix multiplication

题目链接 题意: 给两个n*n的矩阵,求乘积后对3取摸的结果(1≤n≤800) 分析: 考虑一下为什么给3呢,对3取摸只可能得到0.1.2,都可以看作两位的,那么在乘法的时候我们可以用分配率将原来的矩阵乘法分成四个矩阵乘法,每个矩阵都只包括0和1.对于0/1矩阵的乘法,可以使用bitset来快速运算 const int MAXN = 801; bitset<MAXN> r1[MAXN], r2[MAXN], c1[MAXN], c2[MAXN]; int a[MAXN][MAXN]; int

HDU 4902 Matrix multiplication

点击打开链接 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2113    Accepted Submission(s): 956 Problem Description Given two matrices A and B of size n×n, find the product o

POJ 3318 Matrix Multiplication(随机化算法)

给你三个矩阵A,B,C.让你判断A*B是否等于C. 随机一组数据,然后判断乘以A,B之后是否与乘C之后相等. 很扯淡的啊,感觉这种算法不严谨啊... Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16255   Accepted: 3515 Description You are given three n × n matrices A, B and C. Does the e

uva442-Matrix Chain Multiplication

 Matrix Chain Multiplication  Suppose you have to evaluate an expression like A*B*C*D*E where A,B,C,D and E are matrices. Since matrix multiplication is associative, the order in which multiplications are performed is arbitrary. However, the number o