Hdu 4920矩阵乘法(内存访问的讲究)
Matrix multiplication
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2143 Accepted Submission(s): 967Problem DescriptionGiven 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.
InputThe 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).
OutputFor each tests:Print n lines. Each of them contain n integers -- the matrix A×B in similar format.
Sample Input10120 12 34 56 7Sample Output00 12 1
请看完这篇博文,看完就去AC吧。加了输入优化,效果并不明显。
/*************************************************************************
> 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矩阵乘法(内存访问的讲究)的更多相关文章
- *HDU 1757 矩阵乘法
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 4920 矩阵乘积 优化
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- hdu 3483 矩阵乘法
这个题目上周对抗赛题目,搞了我好久 对数学这种不是很敏感 其实都不是自己想出来的,看其他的资料和博客的推导 还是有点难度的,反正我是推不出来 通过二项式定理的化简 有两个博客写得比较好 http:// ...
- HDU 4920 Matrix multiplication 题解(内存访问连续性/卡常)
题目链接 题目大意 多组输入,给你两个n×n的矩阵,要你求他们相乘%3的值 题目思路 这个题目主要是要了解内存访问连续化,要尽量每次访问连续的内存 所以第一种方法会超时,第二种则AC.一种卡常技巧 代 ...
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)
传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...
- HDU 5607 graph(DP+矩阵乘法)
[题目链接] http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=663&pid=1002 [题意] 给定一个有向 ...
- HDU 2604 Queuing (矩阵乘法)
Queuing Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 5863 cjj's string game (矩阵乘法优化递推)
题目大意:用k种字符构建两个长度为n的字符串(每种字符有无限多个),要求对应位置字符相同的连续子串最长长度为m,问方法数. 其中k,n,m是输入,n(1<=n<=1000000000), ...
- Hdu 2157 How many ways??(DP||矩阵乘法)
How many ways?? Time Limit:1000 MS Memory Limit: 32768 K Problem Description 春天到了, HDU校园里开满了花, 姹紫嫣红, ...
随机推荐
- PAT甲级——A1009 Product of Polynomials
This time, you are supposed to find A×B where A and B are two polynomials. Input Specification: Each ...
- 05_jQuery对象初识(三)登录案例
1.案例需求:点击登录按钮验证用户名和密码都不为空,为空就在对应的input标签下面显示一个错误的提示信息. 1.给登录的按钮绑定点击事件 2.点击事件要做的事情 1.找到input标签.取值.判断是 ...
- springcloud(二):Eureka服务注册与发现
Spring Cloud Netflix 该项目是Spring Cloud的子项目之一,主要内容是对Netflix公司一系列开源产品的包装,它为Spring Boot应用提供了自配置的Netflix ...
- RocketMQ补偿方案架构设计
RocketMQ作为消息中间件,在系统异步化架构中,应用非常广泛.但是我们在享用RocketMQ的同时,也不能百分百完全信赖它.一旦RocketMQ崩溃了,给我们业务带来的也将是毁灭性打击. 因此,我 ...
- 07-img和a标签
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- pip报错ImportError: cannot import name main
编辑pip sudo gedit /usr/bin/pip 修改pip文件: 源文件 from pip import main if __name__ == '__main__': sys.exit( ...
- UITableViewHeaderFooterView can't change custom background when loading from nib
down voteforite I've created a custom UITableViewHeaderFooterView and successfully load from nib int ...
- java基础之自定义单链表练习
一.单链表 1.单链表是一种链式存取的数据结构,用一组地址任意的存储单元存放线性表中的数据元素.链表中的数据是以结点来表示的,每个结点的构成:元素(数据元素的映象) + 指针(指示后继元素存储位置), ...
- jmeter体系结构
jmeter体系结构 jmeter体系结构: 1.取样器.断言.监听器组合在一起就可以帮助我们完成发送请求.验证结果及记录结果三项工作 (1)取样器的访问路径:[测试计划]---[线程组] ...
- 2019-8-30-BAT-脚本判断当前系统是-x86-还是-x64-系统
title author date CreateTime categories BAT 脚本判断当前系统是 x86 还是 x64 系统 lindexi 2019-08-30 08:47:40 +080 ...