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

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. 文件夹IsShow字段为空

    IsShow为YesNo字段,默认值为Yes:在Library中新建一个文件的时候会给出默认值yes,但是新建一个文件夹的时候,默认为空,所以f.Item["IsShow"]为空, ...

  2. MVC 中的Areas支持

    在ASP.NET MVC 2中对于Area功能的增强,这样的增强是如何在同一个项目中更好地组织应用程序的? ASP.NET MVC 1.0时,如果我们要在一个项目中做自己网站的后台应用,而又保持URL ...

  3. 使用本地光盘安装Microsoft .NET Framework 3.5 for Win8/WinServer2012

    如何使用本地源安装Microsoft .NET Framework 3.5 作为SQL Server 2012的 必要组件,校验组件过程有个小BUG,即使没有安装也通过,但会卡在安装环节(enabli ...

  4. JSP include HTML出现乱码

    解决方法:在项目的web.xml中加入下面语句:<jsp-config>     <jsp-property-group>     <description>    ...

  5. PLSQL常用时间函数

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

  6. map函数(转)

    STL中map用法详解 说明:如果你具备一定的C++ template知识,即使你没有接触过STL,这个文章你也应该可能较轻易的看懂.本人水平有限,不当之处,望大家辅正. 一.Map概述 Map是ST ...

  7. Codeforces 549C The Game Of Parity(博弈)

    The Game Of Parity Solution: 这个题只需要分类讨论就可以解决. 先分别统计奇数和偶数的个数. 然后判断谁走最后一步,如果走最后一步时候同时有偶数和奇数,那么走最后一步的赢. ...

  8. ACM HDU 1021 Fibonacci Again

    #include<iostream> using namespace std; int main() { int n; while(cin>>n) { if((n+1)%4== ...

  9. tp接支付宝接口签名不相等解决办法 接口版本3.3 tp版本3.1

    (2)在Core.php和Notify.php文件中添加了去掉TP的URL中的'_URL_'参数的函数.这个是必须的,否则会导致验证失败问题.具体改变为: function paraFilter改为 ...

  10. PHP 编译问题PEAR package PHP_Archive not installed的解决

    php 的编译时需要依赖pear package ,目前的问题错误"PEAR package PHP_Archive not installed",已经明显报出这个问题. 因此编译 ...