题目链接

Matrix multiplication

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

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
请看完这篇博文,看完就去AC吧。加了输入优化,效果并不明显。
Accepted Code:
 /*************************************************************************
> File Name: 1010.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年08月05日 星期二 19时22分23秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; int n;
int a[][], b[][], c[][]; int read() {
int res = ;
char c = ' ';
while (c < '' || c > '') c = getchar();
while (c >= '' && c <= '') res += c - '', c = getchar();
return res%;
} int main(void) {
while (~scanf("%d", &n)) {
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
a[i][j] = read();
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
b[i][j] = read();
memset(c, , sizeof(c));
for (int i = ; i < n; i++) {
for (int k = ; k < n; k++) {
for (int j = ; j < n; j++) {
c[i][j] += a[i][k] * b[k][j]; //注意这里的循环顺序
}
}
}
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
printf("%d%c", c[i][j]%, j == n- ? '\n' : ' ');
}
return ;
}

Hdu 4920矩阵乘法(内存访问的讲究)的更多相关文章

  1. *HDU 1757 矩阵乘法

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  2. HDU 4920 矩阵乘积 优化

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

  3. hdu 3483 矩阵乘法

    这个题目上周对抗赛题目,搞了我好久 对数学这种不是很敏感 其实都不是自己想出来的,看其他的资料和博客的推导 还是有点难度的,反正我是推不出来 通过二项式定理的化简 有两个博客写得比较好 http:// ...

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

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

  5. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

  6. HDU 5607 graph(DP+矩阵乘法)

    [题目链接] http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=663&pid=1002 [题意] 给定一个有向 ...

  7. HDU 2604 Queuing (矩阵乘法)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  8. HDU 5863 cjj's string game (矩阵乘法优化递推)

    题目大意:用k种字符构建两个长度为n的字符串(每种字符有无限多个),要求对应位置字符相同的连续子串最长长度为m,问方法数. 其中k,n,m是输入,n(1<=n<=1000000000), ...

  9. Hdu 2157 How many ways??(DP||矩阵乘法)

    How many ways?? Time Limit:1000 MS Memory Limit: 32768 K Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, ...

随机推荐

  1. Java+微信支付(下预购单+回调+退款+查询账单)

    前言: 现在的APP的离不开微信支付, 现在项目里接入微信支付 , 微信支付的官方文档是:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chap ...

  2. 《DSP using MATLAB》Problem 8.8

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  3. myeclipse工程更新后java图标变为空心的解决办法

    今天用svn更新了工程发现目录结构改变了,同时所有的java文件的图标变成了空心的.解决办法如下 1.右键单击工程目录名,选择properties. 2.选择java bulid path,正常的应该 ...

  4. odoo many2one

    在xml中使many2one字段  不可点击 不可跳转 options="{'no_open': True, 'no_create': True}"

  5. Flink 1.9 实战:使用 SQL 读取 Kafka 并写入 MySQL

    上周六在深圳分享了<Flink SQL 1.9.0 技术内幕和最佳实践>,会后许多小伙伴对最后演示环节的 Demo 代码非常感兴趣,迫不及待地想尝试下,所以写了这篇文章分享下这份代码.希望 ...

  6. 中国 SaaS 企业如何突围?这几点是关键!

    进入2019年,关于SaaS的各种言论甚嚣尘上,有人看好:“SaaS市场得大客户者得天下”,也有人唱衰:“SaaS已死,下一个”.在众说纷纭中,中国SaaS企业的成功之路迷雾重重,前期走的较早的头部S ...

  7. 组件:slot插槽

    <!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...

  8. 016-WebDriver API(2)

    1. 多表单切换 WebDriver只能在一个页面上对元素进行识别和定位,无法直接定位frame/iframe表单内嵌页面上的元素,这是就需要通过switch_to.frame()方法将当前定位的主体 ...

  9. Oracle时间日期处理方法

    https://www.cnblogs.com/plmm/p/7381496.html 1.用于截取年.月.日.时.分.秒 extract()函数 extract(year from sysdate) ...

  10. 2019-3-8-win10-uwp-一张图说明水平对齐和垂直对齐

    title author date CreateTime categories win10 uwp 一张图说明水平对齐和垂直对齐 lindexi 2019-03-08 10:45:40 +0800 2 ...