题目链接

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. Acer电脑【no bootable device】引导修复

    时隔一年,又遇上了我的电脑出现     No Bootable Device    的开机提示,进不了系统. 那么怎么办呢? // 本文修复方式仅针对宏碁电脑且分区表为MBR的情况.按如下方法引导并未 ...

  2. mysql 根据时间查询 格式转换竟然要注意大小写,天坑

    时间需要转换格式在查询 查询2018年12月24日以后的记录 SELECT id FROM t_client_info WHERE DATE_FORMAT(visit_datetime,'%Y-%m- ...

  3. C#用API可以改程序名字

    [DllImport("user32.dll", EntryPoint = "FindWindow")] public static extern int Fi ...

  4. GitHub for Visual Studio使用讲解

    从VS2015起(应该是吧?),微软已经在VS中集成了GitHub,方便开发者对项目进行版本控制. 扩展包下载地址:https://aka.ms/ghfvs 其实VS2015的安装包中已经自带了这个扩 ...

  5. 解决Couldn't resolve host 'mirrorlist.centos.org

    这个错误引起主要是因为环境读取不到yun引起的可以考虑/etc/sysconfig/network-scripts/ifcfg-eth0 配置出错导致网络不通.或者/etc/resolv.conf的D ...

  6. python print输出format太好用了

    不用担心什么其他的东西了,直接用format: print("{}的Ground,Detected,DetectedRight个数分别为{},{},{},".format(cate ...

  7. poj2406

    求循环节之类的问题 #include<iostream> #include<cstdio> #include<queue> #include<algorith ...

  8. 阿里云 Aliplayer高级功能介绍(九):自动播放体验

    基本介绍 经常会碰到客户询问,为什么我设置了autoplay为true,但是没有自动播放,每次都要向客户解释这个是浏览器从用户体验角度考虑做的限制,客户会继续询问那我要怎么做? 针对这个问题Alipl ...

  9. Django项目:CMDB(服务器硬件资产自动采集系统)--09--06CMDB测试Linux系统采集硬件数据的命令04

    root 123456 ip addr init 0 root 123456 ip addr root 123456 python3 yum -y install zlib-devel bzip2-d ...

  10. vue.js_05_vue.js的过滤器

    1.过滤器的定义和使用 实现:将页面的中的单纯替换成,用户传来的文字. 全局过滤器:所有的Vue对象都可以使用 <body> <div id="app"> ...