HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵
Matrix multiplication
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1775 Accepted Submission(s):
796
product of them.
bobo hates big integers. So you are only asked to find
the result modulo 3.
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).
Print n lines. Each of them
contain n integers -- the matrix A×B in similar format.
#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 矩阵相乘。稀疏矩阵的更多相关文章
- HDU 4920 Matrix multiplication(矩阵相乘)
各种TEL,233啊.没想到是处理掉0的情况就能够过啊.一直以为会有极端数据.没想到居然是这种啊..在网上看到了一个AC的奇妙的代码,经典的矩阵乘法,仅仅只是把最内层的枚举,移到外面就过了啊...有点 ...
- HDU 4920 Matrix multiplication(bitset)
HDU 4920 Matrix multiplication 题目链接 题意:给定两个矩阵,求这两个矩阵相乘mod 3 思路:没什么好的想法,就把0的位置不考虑.结果就过了.然后看了官方题解,上面是用 ...
- hdu 4920 Matrix multiplication(矩阵乘法)2014多培训学校5现场
Matrix multiplication Time ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- HDU 4920 Matrix multiplication(bitset优化)
题目链接 Matrix multiplication 求矩阵A和B相乘的结果. 因为答案只要对3取模,所以我们可以通过一些方法来加速计算. 我们对两个矩阵各开两个bitset,分别存储模3余1和模3余 ...
- hdu - 4920 - Matrix multiplication(缓存优化+开挂)
题意:求两个n x n的矩阵相乘后模3的结果,n <= 800. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 -->>呀呀 ...
- 2014多校第五场1010 || HDU 4920 Matrix multiplication(矩阵乘法优化)
题目链接 题意 : 给你两个n*n的矩阵,然后两个相乘得出结果是多少. 思路 :一开始因为知道会超时所以没敢用最普通的方法做,所以一直在想要怎么处理,没想到鹏哥告诉我们后台数据是随机跑的,所以极端数据 ...
- HDU 4920 Matrix multiplication (硬件优化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4920 解题报告:求两个800*800的矩阵的乘法. 参考这篇论文:http://wenku.baidu ...
- HDU 4920 Matrix multiplication 题解(内存访问连续性/卡常)
题目链接 题目大意 多组输入,给你两个n×n的矩阵,要你求他们相乘%3的值 题目思路 这个题目主要是要了解内存访问连续化,要尽量每次访问连续的内存 所以第一种方法会超时,第二种则AC.一种卡常技巧 代 ...
随机推荐
- Hdu-3487 Splay树,删除,添加,Lazy延迟标记操作
HDU_3487 题意:给出n和q,n代表1-n的序列,接下来q有两种操作,Cut a b c:表示把区间[a,b]截掉然后放在第c个数的后面,Flip a b 表示把区间[a,b]反转,经过一系列的 ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- C++多线程调试和测试的注意事项
在一个程序中,这些独立运行的程序片断叫作“线程”(Thread),利用它编程的概念就叫作“多线程处理”.利用线程,用户可按下一个按钮,然后程序会立即作出响应,而不是让用户等待程序完成了当前任务以后才开 ...
- springday03-go2
新建springmvc01项目1.创建项目,导入jar包 拷贝jar/spring/first下的五个spring的jar包,以及jar/spring/mvc下的两个mvcjar包放在lib下 2.创 ...
- [php] How to debug PHP in the terminal
Here I use Netbeans, xdebug to debug the PHP in the terminal of Ubuntu. 1. you have to install the x ...
- 关于centos更新后virtualbox无法使用的问题
http://blog.csdn.net/zgglj/article/details/50325675
- 在linux中搭建git服务器
个人觉得, 以下搭建git服务器的过程就像是在linux增加了一个用户, 而这个用户的登录shell是 git-shell, 太刨根问底的东西我也说不清楚, 还是看下面的过程吧. 过程参考了网上的文章 ...
- Server2003系统上的内置服务器设置某类IP无法访问问题
最近测试过程中遇到了一个很奇怪的现象,把服务器(测试产品)部署在Server2003系统的外网A上,把客户端(测试产品)部署在内网B,网络A,B用路由器相连,设置网络A为200.1.1.255,发现客 ...
- MYSQL 、Oracle、SQLServer 数据库中时间的格式化输出
在MYSQL 中格式化输出 date_forma t(date,'yyyyMMddHHmmss') Oracle 中格式化输出 to_char(time ,'yyyyMMddHHmmss') SQL ...
- 【转】ubuntu64,ndk-r9 编译 ffmpeg 2.1.1的config文件
#!/bin/bash NDK_ROOT=/home/wjh/fox/android-ndk-r9c/ PREBUILT=${NDK_ROOT}toolchains/arm-linux-android ...