矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的。神奇小代码。

Matrix multiplication

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1476    Accepted Submission(s): 650

Problem Description
Given two matrices A and B of size n×n, find the product of them.

bobo hates big integers. So you are only asked to find the result modulo 3.

 
Input
The input consists of several tests. For each tests:

The first line contains n (1≤n≤800). Each of the following n lines contain n integers -- the description of the matrix A. The j-th integer in the i-th line equals Aij. The next n lines describe the matrix B in similar format (0≤Aij,Bij≤109).

 
Output
For each tests:

Print n lines. Each of them contain n integers -- the matrix A×B in similar format.

 
Sample Input
1
0
1
2
0 1
2 3
4 5
6 7
 
 
Sample Output
0
0 1
2 1
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[][],b[][],c[][];
int main()
{
int k,i,n,j,x;
while(~scanf("%d",&n))
{
memset(c,,sizeof(c));
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
scanf("%d",&x);
a[i][j]=x%;
}
for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
scanf("%d",&x);
b[i][j]=x%;
}
for(k=; k<=n; k++)
{
for(j=;j<=n; j++)
{
for(i=;i<=n; i++)
{
c[k][i]+=a[k][j]*b[j][i];
}
}
}
for(i=;i<=n; i++)
{
for(j=;j<n; j++)
printf("%d ",c[i][j]%);
printf("%d\n",c[i][n]%);
}
}
return ;
}

HDU-4920 Matrix multiplication的更多相关文章

  1. HDU 4920 Matrix multiplication(bitset)

    HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...

  2. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  4. hdu 4920 Matrix multiplication(矩阵乘法)2014多培训学校5现场

    Matrix multiplication                                                                           Time ...

  5. HDU 4920 Matrix multiplication(矩阵相乘)

    各种TEL,233啊.没想到是处理掉0的情况就能够过啊.一直以为会有极端数据.没想到居然是这种啊..在网上看到了一个AC的奇妙的代码,经典的矩阵乘法,仅仅只是把最内层的枚举,移到外面就过了啊...有点 ...

  6. HDU 4920 Matrix multiplication(bitset优化)

    题目链接 Matrix multiplication 求矩阵A和B相乘的结果. 因为答案只要对3取模,所以我们可以通过一些方法来加速计算. 我们对两个矩阵各开两个bitset,分别存储模3余1和模3余 ...

  7. HDU 4920 Matrix multiplication (硬件优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 解题报告:求两个800*800的矩阵的乘法. 参考这篇论文:http://wenku.baidu ...

  8. hdu - 4920 - Matrix multiplication(缓存优化+开挂)

    题意:求两个n x n的矩阵相乘后模3的结果,n <= 800. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 -->>呀呀 ...

  9. 2014多校第五场1010 || HDU 4920 Matrix multiplication(矩阵乘法优化)

    题目链接 题意 : 给你两个n*n的矩阵,然后两个相乘得出结果是多少. 思路 :一开始因为知道会超时所以没敢用最普通的方法做,所以一直在想要怎么处理,没想到鹏哥告诉我们后台数据是随机跑的,所以极端数据 ...

  10. hdu 4920 Matrix multiplication (矩阵计算)

    题目链接 题意:给两个矩阵a, b, 计算矩阵a*b的结果对3取余. 分析:直接计算时间复杂度是O(n^3),会超时,但是下面第一个代码勉强可以水过,数据的原因. #include <iostr ...

随机推荐

  1. Browser Link: Failed to deserialize JSON in Browser Link call

    问题 VS2013中调试程序发现,在浏览器控制台输出如下截图代码:

  2. Android-The specified child already has a parent. You must call removeView() on the child's parent first.

    这个问题搞了我半天了,网上有很多人说需要找到该控件的parent后,让该parent 先remove需要添加的控件,然后在添加,如: if (view != null) { ViewGroup par ...

  3. EF收集

    http://www.cnblogs.com/end/archive/2011/08/18/2144250.html http://www.cnblogs.com/zzdfc/archive/2009 ...

  4. oracle 过程函数,包的区别和联系

    一.过程与函数区别 1.过程可以有0~N个返回参数,通过OUT or IN OUT参数返回:函数有且仅有1个返回值,通过return语句返回. 2.调用过程时,可做为单独的语句执行:调用函数时,函数必 ...

  5. iOS支付总结

    内容大纲: 一.常见的支付方案简介 二.第三方支付SDK 三.苹果官方支付方案 四.Web支付方案 正文: 一.常见的支付方案简介 在微信支付中 微信支付的网址是: https://pay.weixi ...

  6. js keycode大全

    JS KeyCode数字对应键盘以及应用大全   时间:2014-07-11 10:37    点击:851次 keycode    8 = BackSpace BackSpacekeycode    ...

  7. C++学习笔记-2-构造函数和析构函数

    问题2. 什么时候执行构造函数和析构函数  22:59:40 2015-07-22 做了一个实验: #include <iostream> class Object{ public: Ob ...

  8. State 模式

    State模式中我们将状态逻辑和动作实现进行分离.允许一个对象在其内部状态改变时改变它的行为,对象看起来似乎修改了它的类:在一个状态即将结束的时候启用下一个状态. /////////state.h// ...

  9. CoffeeScript飞一样的写javascript

    之前看到同事在使用coffeescript写js,当我看到那简介的coffee文件,就深深的被coffescript吸引了,简洁的语法,熟练之后会大大提升javascript的开发速度,写脚本也能像飞 ...

  10. 2013年12月26日 星期四 doxygen入门--很好

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...