hdu4920(矩阵 乘法)
来源:互联网 发布:图片纹理算法 编辑:程序博客网 时间:2024/06/05 09:08
题意:矩阵乘法,在乘的过程中每个元素都取模3
在比赛时,我一直在想怎么才能把O(n*n*n)的时间复杂度给降下来,可是一直没想到好的办法,后来看了题解后才知道原来时间复杂度还是O(n*n*n),只是优化了一点而已
代码如下:
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<stack>#include<queue>#include<set>#include<map>#include<stdio.h>#include<bitset>#include<stdlib.h>#include<math.h>#define N 1000#define inf 0x7ffffff#define eps 1e-9#define pi acos(-1.0)using namespace std;int a[N][N],b[N][N],c[N][N];int main(){//freopen("input.txt","r",stdin);//freopen("output.txt","w",stdout); int i,j,k; int n; while(scanf("%d",&n) != EOF) { for(i = 0; i < n; i++) for(j = 0; j < n; j++) { scanf("%d",&a[i][j]); a[i][j] %= 3; } for(i = 0; i < n; i++) for(j = 0; j < n; j++) { scanf("%d",&b[i][j]); b[i][j] %= 3; } memset(c,0,sizeof(c)); for(i = 0; i < n; i++) for(k = 0; k < n; k++) { if(a[i][k] == 0) continue; for(j = 0; j < n; j++) c[i][j] = (c[i][j] + a[i][k]*b[k][j])%3; } for(i = 0; i < n; i++){ int flag = 0; for(j = 0; j < n; j++) if(flag == 0) { printf("%d",c[i][j]); flag = 1; } else printf(" %d",c[i][j]); printf("\n"); } } return 0;}
0 0
- hdu4920(矩阵 乘法)
- hdu4920 矩阵乘法%3
- HDU4920 矩阵乘法
- HDU4920矩阵乘法优化之转置
- hdu4920 Matrix multiplication [矩阵乘法 压位 ]
- 矩阵乘法优化--hdu4920 滚动数组
- HDU4920 Matrix multiplication 矩阵
- 【codevs1287】矩阵乘法(矩阵乘法)
- 【codevs1287】矩阵乘法(矩阵乘法)
- hdu4920 滚动数组的矩阵相乘
- 矩阵乘法(矩阵)【hpu】
- 矩阵乘法(一)
- 51nod 1137 矩阵乘法(矩阵快速乘法)
- 51nod 1137 矩阵乘法(矩阵乘法)
- 矩阵 模板(矩阵加减,矩阵乘法,矩阵求逆)
- poj3070(矩阵快速幂,矩阵乘法)
- poj 3233 矩阵乘法(分块矩阵)
- HDU5950Recursive sequence(构造矩阵+矩阵乘法)
- JS的functioin
- leetcode 刷题之路 50 Unique Binary Search Trees II
- diff
- 单片机中的sbit
- mysql using() 能用于三张表查询吗,如果不能那用什么
- hdu4920(矩阵 乘法)
- 如何使用ContentResolver
- OC中 NSArray中常用的方法,记住了就不用再看API
- 线段树(待续)(区间每个数加上不同的斐波那契额数)Codeforces Round #FF (Div. 2)E
- android cmd adb命令安装和删除apk应用
- UriMatcher类使用介绍
- tmp
- 腾达路由器WISP功能小测试
- Andorid 引入Lib后 ClassNotFoundException解决办法