Matrix multiplication

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

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
 
Author
Xiaoxu Guo (ftiasch)
 
Source
 
Recommend
We have carefully selected several similar problems for
you:  4919 4918 4917 4916 4915 
 
 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std; struct Matrix
{
int mat[][];
}hxl,tom,now;
void solve(int n)
{
int i,j,k;
for(i=;i<=n;i++)
{
for(k=;k<=n;k++)
{
if(hxl.mat[i][k]==) continue;
for(j=;j<=n;j++)
{
now.mat[i][j] = now.mat[i][j] + hxl.mat[i][k]*tom.mat[k][j];
}
}
}
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
if(j==)printf("%d",now.mat[i][j]%);
else printf(" %d",now.mat[i][j]%);
}
printf("\n");
}
}
int main()
{
int n;
int i,j;
while(scanf("%d",&n)>)
{
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
scanf("%d",&hxl.mat[i][j]);
hxl.mat[i][j]%=;
now.mat[i][j] = ;
}
for(i=;i<=n;i++)
for(j=;j<=n;j++)
{
scanf("%d",&tom.mat[i][j]);
tom.mat[i][j]%=;
}
solve(n); }
return ;
}

HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵的更多相关文章

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

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

  2. HDU 4920 Matrix multiplication(bitset)

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

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

    Matrix multiplication                                                                           Time ...

  4. hdu 4920 Matrix multiplication bitset优化常数

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

  5. HDU 4920 Matrix multiplication(bitset优化)

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

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

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

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

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

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

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

  9. HDU 4920 Matrix multiplication 题解(内存访问连续性/卡常)

    题目链接 题目大意 多组输入,给你两个n×n的矩阵,要你求他们相乘%3的值 题目思路 这个题目主要是要了解内存访问连续化,要尽量每次访问连续的内存 所以第一种方法会超时,第二种则AC.一种卡常技巧 代 ...

随机推荐

  1. git的基本使用

    1.在本地新建一个文件夹来存放代码 2.用命令行进入这个文件夹 3.git init --来创建一个代码仓库 3. 配置用户信息:用户名和 邮箱(联系作者本人沟通, 责任到人) git config ...

  2. UML: 活动图

    摘自http://www.umlonline.org/school/thread-36-1-1.html 活动图和流程图很类似,我们看看一个流程图的例子: 活动图是用来描述流程的一种图,它与流程图的不 ...

  3. Hbase HRegionServer启动后自动关闭

    突然发现HBASE无法使用了. 然后看到在分布式的情况下,节点上的HRegionServer启动后自动关闭. 同步时间就能解决这个问题. 网上同步时间 1.  安装ntpdate工具 sudo apt ...

  4. LIKE 某个变量

    declare i ); n number; begin i:='%D0FC02EAR11005%'; select po_header_id into n from po_headers_all w ...

  5. jquery表格仿菜单

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  6. PAT乙级 1020. 月饼 (25)(只得到23分)

    1020. 月饼 (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 月饼是中国人在中秋佳节时吃的一种传统食 ...

  7. TortoiseGit文件夹和文件图标不显示解决方法

    试了两种方法, 1.修改Max Cached Icons http://www.open-open.com/lib/view/open1414396787325.html 2.修改图标排序 http: ...

  8. Loadrunner教程读后感-VuGen

    一.loadrunner协议分析 协议确定方法 二.提交表单函数的区别 (1)web_sumit_form() (2)web_sumit_data() 三.web_url和web_link 四.VuG ...

  9. 使用QTP对Flight的登录界面进行测试

    一.测试用例设计 现在使用QTP对案例程序进行测试, 设计测试用例的要求为: 用户名长度大于等于6个字符 必须为字母[o-z,O-Z]和数字[0-9]组成 不能为空,空格或者特殊字符 正确的密码为:M ...

  10. rqnoj-342-最不听话的机器人-dp

    dp[i][j][k][[l]: 执行第i步,执行到点(j,k),方向为l时,用的最大步数. 状态转移根据step[i]转移. #include<stdio.h> #include< ...