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. 转:Java的各种类型转换汇总

    java类型转换 Integer String Long Float Double Date 1如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Intege ...

  2. 字典:NSDictionary的应用举例

    字典就是关键字及其定义(描述)的集合.Cocoa中的实现字典的集合NSDictionary在给定的关键字(通常是一个NSString)下存储一个数值(可以是任何类型的对象).然后你就可以用这个关键字来 ...

  3. WebDriver:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

    今天尝试最新的webDriver与fireFox搭配: 运行代码时出现如下的问题,但是浏览器却可以打开: org.openqa.selenium.firefox.NotConnectedExcepti ...

  4. Android 仿土巴兔选择效果

    1,前两天在群里看到有人在讨论土巴兔的选择装修风格的效果,自己也想实现,果断百度一下,有些好的文章,就花了些时间来分析了下,先看看别人土巴兔原装的功能 2,可以看到,基本上可以使用一个vviewpag ...

  5. Bootstrap布局设计

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  6. visualvm添加远程管理-centos

    VisualVM连接远程服务器有两种方式:JMX和jstatd,两种方式都不能完美支持所有功能,例如JMX不支持VisualGC,jstatd不支持CPU监控,实际使用可同时配置上并按需选用. 1.修 ...

  7. Java中的json数据类型操作

    package com.ss1.json; import java.util.ArrayList; import java.util.HashMap; import java.util.List; i ...

  8. [CrunchBang]中文字体美化

    安装必要的字体包 sudo apt-get install ttf-droid ttf-wqy-zenhei xfonts-wqy ttf-wqy-microhei ttf-arphic-ukai t ...

  9. hadoop之输入输出格式

    <STRONG>jobConf.setInputFormat(MyInputFormat. class ); InputFormat:</STRONG> TextInputFo ...

  10. django form使用学习记录

    Django forms使用容易, 又方便扩展, 因此Django admin和CBVs基本都基于forms使用. 事实上, 由于django forms的强大验证功能, 大多数Django API ...