Matrix Multiplication(找规律)
来源:互联网 发布:怕死 陈奕迅 知乎 编辑:程序博客网 时间:2024/05/22 00:51
Let us consider undirected graph G = which has N vertices and M edges. Incidence matrixof this graph is N * M matrix A = {aij}, such that aij is 1 if i-th vertex is one of the ends of j-th edgeand 0 in the other case. Your task is to find the sum of all elements of the matrix ATA.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains two integer numbers - N and M (2 <= N <= 10 000, 1 <= M <= 100 000). 2M integer numbers follow, forming M pairs, each pair describes one edge of the graph. Alledges are different and there are no loops (i.e. edge ends are distinct).
Output
Output the only number - the sum requested.
Sample Input
1
4 4
1 2
1 3
2 3
2 4
Sample Output
18
题解:T组数据,n,m,然后m行边,根据m行边转换成一个n行m列的矩阵,求这个矩阵的转置矩阵乘以此矩阵的出来的矩阵的元素之和……
比赛的时候一看题目,矩阵相乘,一脸懵逼,不会,赶紧找了本线代书看了下,看了半个小时终于懂了,但一看数据范围,我了个大草,这怎么存图,怎么运算,肯定妥妥的双超……
赛后看了下别人的的代码……我心中一万只国宝奔腾而过……不过还是没弄懂什么意思,如果哪位大神知道,请拯救一下迷途的羔羊……
#include<bits/stdc++.h>#include<cstdio>#include<iostream>#include<algorithm>#include<string.h>#include<stdlib.h>#include<time.h>#include<string>#include<math.h>#include<map>#include<queue>#include<stack>#define INF 0x3f3f3f3f#define ll long long#define For(i,a,b) for(int i=a;i<b;i++)#define sf(a) scanf("%d",&a)#define sfs(a) scanf("%s",a)#define sff(a,b) scanf("%d%d",&a,&b)#define sfff(a,b,c) scanf("%d%d%d",&a,&b,&c)#define pf(a) printf("%d\n",a)#define mem(a,b) memset(a,b,sizeof(a))using namespace std;int x[10005];int main(){ int t,n,m,falg=0; sf(t); while(t--) { if(falg)printf("\n");falg=1; mem(x,0); sff(n,m); int a,b; For(i,0,m) { sff(a,b); x[a]++;x[b]++; } ll s=0; For(i,1,n+1) { s+=x[i]*x[i]; } cout<<s<<endl; }}
- Matrix Multiplication(找规律)
- ZOJ2316 Matrix Multiplication(找规律)
- ACdream 1213 Matrix Multiplication【水题 、 找规律】
- ZOJ 2316 Matrix Multiplication(找规律)(矩阵和它的转置矩阵之积)
- POJ 2505 A multiplication game(找规律博弈)
- poj 2505 A multiplication game (博弈+找规律)
- HDU 4951 Multiplication table(找规律)
- Matrix multiplication(bitset)
- HDU 1517 ——A Multiplication Game(博弈)(找规律)
- HDU 1517 A Multiplication Game (博弈、PN态、找规律)*
- hdu 1517 A Multiplication Game (博弈——找规律)
- hdu 1517 A Multiplication Game(博弈找规律)
- 【POJ 2505】A multiplication game 博弈 - 找规律
- HDU 1517 A Multiplication Game(博弈找规律)
- HDU 1517 A Multiplication Game 博弈论+找规律
- HDU 4920 (Matrix multiplication)
- HDOJ1021(找规律)
- POJ1740(找规律)
- HDOJ 5410 01背包+完全背包
- c++第二天
- 《C++ primer plus》附录G:STL方法与函数(一) 学习笔记
- webstorm2016.2激活方法
- 使用jdk和cglib实现动态代理
- Matrix Multiplication(找规律)
- TreeSet集合
- C++之虚析构函数
- ZOJ
- C++中bitset的使用
- cv::Mat 对像素进行操作取地址
- 数据结构与算法---栈
- css的6大布局方式
- 这个前端面试在搞事!