HDU 4920 Matrix multiplication 解题报告(暴力)
来源:互联网 发布:剑网3菊花插件数据 编辑:程序博客网 时间:2024/05/24 07:04
Matrix multiplication
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 862 Accepted Submission(s): 343
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.
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).
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.
Print n lines. Each of them contain n integers -- the matrix A×B in similar format.
Sample Input
10120 12 34 56 7
Sample Output
00 12 1
Author
Xiaoxu Guo (ftiasch)
Source
2014 Multi-University Training Contest 5
解题报告:直接乘的复杂度略高,优化一点就可以过了。这里统计按行来计算了,代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <iomanip>using namespace std;#define ff(i, n) for(int i=0;i<(n);i++)#define fff(i, n, m) for(int i=(n);i<=(m);i++)#define dff(i, n, m) for(int i=(n);i>=(m);i--)#define bit(n) (1LL<<(n))typedef long long LL;typedef unsigned long long ULL;const LL inf=1e15;void work();int main(){#ifdef ACM freopen("input.in", "r", stdin);// freopen("input.in", "w", stdout);#endif // ACM work();}/***************************************************/int a[888][888];int b[888][888];int ans[888];int last[888];int n, tmp;void add(int * x, int * y){ ff(i, n) x[i] += y[i];}void sub(int * x, int * y){ ff(i, n) x[i] -= y[i];}void work(){ while(scanf("%d", &n) == 1) { ff(i, n) ff(j, n) scanf("%d", &tmp), a[i][j] = tmp%3; ff(i, n) ff(j, n) scanf("%d", &tmp), b[i][j] = tmp%3; memset(ans, 0, sizeof(ans)); memset(last, 0, sizeof(last)); ff(i, n) { ff(j, n) { if(a[i][j] - last[j] == 1 || a[i][j] - last[j] == -2) add(ans, b[j]); else if(a[i][j] - last[j] == -1 || a[i][j] - last[j] == 2) sub(ans, b[j]); last[j] = a[i][j]; } ff(j, n) ans[j] = (ans[j]%3+3)%3; printf("%d", ans[0]); fff(j, 1, n-1) printf(" %d", ans[j]); puts(""); } }}
0 0
- HDU 4920 Matrix multiplication 解题报告(暴力)
- Matrix Multiplication解题报告
- HDU 4920 Matrix multiplication 暴力(bitset)
- HDU 4920 (Matrix multiplication)
- POJ 3318 Matrix Multiplication 解题报告 (随机化 & 矩阵性质)
- UVa 442 - Matrix Chain Multiplication解题报告
- 【Jason's_ACM_解题报告】Matrix Chain Multiplication
- [leetcode] 311. Sparse Matrix Multiplication 解题报告
- POJ 2246 Matrix Chain Multiplication 解题报告
- [Leetcode] 311. Sparse Matrix Multiplication 解题报告
- hdu 4920 Matrix multiplication
- HDU 4920 Matrix multiplication
- hdu 4920 Matrix multiplication
- HDU 4920 Matrix multiplication
- HDU 4920 Matrix multiplication
- HDU-4920-Matrix multiplication
- HDU 4920 Matrix multiplication
- HDU-4920 Matrix multiplication
- leetcode Best Time to Buy and Sell Stock(I~III)(*)
- iOS页面跳转及数据传递
- poj 3252(详解)
- 没有窗口怎么解决SetTimer问题
- 拓扑排序
- HDU 4920 Matrix multiplication 解题报告(暴力)
- (4.4.1)使用storyboard实现页面跳转,简单的数据传递
- 在linux下设置共享库路径
- Node.js使用Sequelize ORM框架
- 微处理器之Trace Cache浅析
- 计算工资
- 树状数组应用:区间去重求和 hdoj 3333
- ios ViewController 页面跳转
- 从零开始学习OpenWrt完美教程(中文站镜像)