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=; i<=n; i++)
ans+=ll(d[i])*(d[i]-);
cout<<ans<<endl;
return ;
}
SGU196_Matrix Multiplication的更多相关文章
- POJ2505 A multiplication game[博弈论]
A multiplication game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6028 Accepted: ...
- 【数学】Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total S ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 矩阵乘法 --- hdu 4920 : Matrix multiplication
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Booth Multiplication Algorithm [ASM-MIPS]
A typical implementation Booth's algorithm can be implemented by repeatedly adding (with ordinary un ...
- hdu4951 Multiplication table (乘法表的奥秘)
http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- poj 1651 Multiplication Puzzle (区间dp)
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of ca ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...
随机推荐
- 源码阅读笔记 - 1 MSVC2015中的std::sort
大约寒假开始的时候我就已经把std::sort的源码阅读完毕并理解其中的做法了,到了寒假结尾,姑且把它写出来 这是我的第一篇源码阅读笔记,以后会发更多的,包括算法和库实现,源码会按照我自己的代码风格格 ...
- redmine 配置邮件发送为async后,不能发送邮件(转载)
通过参考:http://www.oschina.net/question/2005703_16688 之前configuration.yaml文件中email的相关配置如下: production: ...
- Eclipse启动Tomcat后无法访问项目
Eclipse中的Tomcat可以正常启动,不过发布项目之后,无法访问,包括http://localhost:8080/的小猫页面也无法访问到,报404错误.这是因为Eclipse所指定的Server ...
- string.Format之你不知道的事
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
- Spring container vs SpringMVC container(webmvc container)
Difference between applicationContext.xml and spring-servlet.xml in Spring Framework Scenario 1 In c ...
- c#lock语句及在单例模式中应用
C#中的lock语句是怎么回事,有什么作用? C#中的lock语句将lock中的语句块视为临界区,让多线程访问临界区代码时,必须顺序访问.他的作用是在多线程环境下,确保临界区中的对象只被一个线程操作, ...
- 天嵌E8卡片电脑USBWIFI驱动linux移植
下载驱动:http://pan.baidu.com/s/1sjL0Axn The drivers can be downloaded from Ralink website, the present ...
- python 版本问题大全
坑一 一下午的时间又让这个不是问题的问题给白白给浪费了,此片文章仅仅纪念一下浪费掉的宝贵时间 新式类与经典类问题 class qwe: def __init__(self, name): self.n ...
- PCI Express(三) - A story of packets, stack and network
原文出处:http://www.fpga4fun.com/PCI-Express3.html Packetized transactions PCI express is a serial bus. ...
- JS 退出系统并跳转到登录界面的实现代码
js代码如下: <script language="javascript" type="text/javascript"> function log ...