SGU - 196 - Matrix Multiplication (矩阵乘法)
来源:互联网 发布:足球彩票哪个软件好 编辑:程序博客网 时间:2024/05/17 23:31
196. Matrix Multiplication
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
memory limit per test: 65536 KB
input: standard
output: standard
output: standard
Let us consider an undirected graph G = <V, E> which has N vertices and M edges. Incidence matrix of this graph is an N × M matrix A = {aij}, such that aij is 1 if i-th vertex is one of the ends of j-th edge and 0 in the other case. Your task is to find the sum of all elements of the matrix ATA where AT is A transposed, i.e. an M × N matrix obtained from A by turning its columns to rows and vice versa.
Input
The first line of the input file contains two integer numbers — N and M (2 le N le 10,000, 1 le M le 100,000). 2M integer numbers follow, forming M pairs, each pair describes one edge of the graph. All edges are different and there are no loops (i.e. edge ends are distinct).
Output
Output the only number — the sum requested.
Sample test(s)
Input
4 4 1 2 1 3 2 3 2 4
Output
18
[submit]
[forum]
思路:自己手动执行几下就可以发现规律,这里存储图中边的方法为完全关联矩阵(离散数学中有介绍),而本题的规律为只要统计每个定点的出现次数的平方即可
AC代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define LL long longusing namespace std;int num[10005];int N, M;int main() {while(scanf("%d %d", &N, &M) != EOF) {memset(num, 0, sizeof(num));for(int i = 0; i < M; i++) {int a, b;scanf("%d %d", &a, &b);num[a]++, num[b]++;}LL ans = 0;for(int i = 1; i <= N; i++) {ans += (num[i] * num[i]);}cout << ans << endl;}return 0;}
1 0
- SGU - 196 - Matrix Multiplication (矩阵乘法)
- HDU 4920 Matrix multiplication(矩阵乘法)
- hdu 4920 Matrix multiplication(矩阵乘法)
- POJ3318 Matrix Multiplication ( 随机化 + 矩阵乘法)
- sgu 196 Matrix Multiplication
- sgu 196 Matrix Multiplication
- hdu4920 Matrix multiplication [矩阵乘法 压位 ]
- HDU 4920 Matrix multiplication(矩阵乘法)
- sgu196:Matrix Multiplication(矩阵乘法-->图)
- ACdream 1213 Matrix Multiplication(矩阵乘法)
- HDU 4920(Matrix multiplication-矩阵乘法优化)
- 向量、矩阵乘法的几何意义(二) 矩阵乘法(Matrix Multiplication)
- HDU 4920 Matrix multiplication(稀疏矩阵的乘法)不优化很容易TLE
- HDU 4920 Matrix multiplication(矩阵乘法,cin,cout超时呀)
- 【4920Matrix multiplication】矩阵乘法优化+输入挂
- Hdu 4920 Matrix multiplication[矩阵乘法的时间复杂度优化]
- 矩阵链乘法问题描述(Matrix-chain multiplication)
- Hdu4920Matrix multiplication(矩阵乘法)
- springmvc如何访问到静态的文件,如jpg,js,css
- bloom filter原理
- 安装java memcached client到maven repository
- 不用临时变量,交换两个数。
- 课程实验1 基于java Socket的C/S小程序
- SGU - 196 - Matrix Multiplication (矩阵乘法)
- 搭建dns
- 结构-03. 平面向量加法(10)
- 用c语言实现输入一个十进制数,计算其转换为二进制数后其中包含1的个数
- [BZOJ 1854][SCOI 2010]游戏(二分图最大匹配)
- go数据库增删改查
- unity particleSystem bug研究
- AutoResetEvent
- 【软件使用】GitHub使用教程for Eclipse