日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4920 Matrix multiplication(矩阵相乘)

發布時間:2023/12/10 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4920 Matrix multiplication(矩阵相乘) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

各種TEL,233啊。沒想到是處理掉0的情況就能夠過啊。一直以為會有極端數據。沒想到居然是這種啊、、在網上看到了一個AC的奇妙的代碼,經典的矩陣乘法,僅僅只是把最內層的枚舉,移到外面就過了啊、、、有點不理解啊,復雜度不是一樣的嗎、、

Matrix multiplication

Time Limit: 4000/2000 MS (Java/Others)????Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 640????Accepted Submission(s): 250


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
Author Xiaoxu Guo (ftiasch)
Source 2014 Multi-University Training Contest 5 #include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include <iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include <stack> #include <map> #include <set> #define eps 1e-12 ///#define M 1000100 #define LL __int64 ///#define LL long long ///#define INF 0x7ffffff #define INF 0x3f3f3f3f #define PI 3.1415926535898 #define zero(x) ((fabs(x)<eps)?

0:x) using namespace std; const int maxn = 810; int a[maxn][maxn]; int b[maxn][maxn]; int c[maxn][maxn]; int aa[maxn][maxn]; int bb[maxn][maxn]; int main() { int n; while(cin >>n) { memset(c, 0, sizeof(c)); memset(aa, 0, sizeof(aa)); memset(bb, 0, sizeof(bb)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { scanf("%d",&a[i][j]); a[i][j] %= 3; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { scanf("%d",&b[i][j]); b[i][j] %= 3; } } for(int i = 1; i <= n; i++) { int x = -1; for(int j = n; j >= 0; j--) { aa[i][j] = x; if(a[i][j]) x = j; } } for(int i = 1; i <= n; i++) { int x = -1; for(int j = n; j >= 0; j--) { bb[i][j] = x; if(b[i][j]) x = j; } } for (int i = 1; i <= n; i++) { for(int j = aa[i][0]; j != -1; j = aa[i][j]) { for(int k = bb[j][0]; k != -1; k = bb[j][k]) c[i][k] += a[i][j]*b[j][k]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n-1; j++) printf("%d ",c[i][j]%3); printf("%d\n",c[i][n]%3); } } return 0; }


這是看到有人交的AC的代碼:

#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int N = 805; int a[N][N], b[N][N], ans[N][N]; int main() {int n, i, j, k;while(~scanf("%d",&n)){for(i = 1; i <= n; i++)for(j = 1; j <= n; j++){scanf("%d",&a[i][j]);a[i][j] %= 3;}for(i = 1; i <= n; i++)for(j = 1; j <= n; j++){scanf("%d",&b[i][j]);b[i][j] %= 3;}memset(ans, 0, sizeof(ans));for(k = 1; k <= n; k++) //經典算法中這層循環在最內層。放最內層會超時,可是放在最外層或者中間都不會超時,不知道為什么for(i = 1; i <= n; i++)for(j = 1; j <= n; j++){ans[i][j] += a[i][k] * b[k][j];//ans[i][j] %= 3; //假設在這里對3取余,就超時了}for(i = 1; i <= n; i++){for(j = 1; j < n; j++)printf("%d ", ans[i][j] % 3);printf("%d\n", ans[i][n] % 3);}}return 0; }

轉載于:https://www.cnblogs.com/yxwkf/p/5418535.html

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的HDU 4920 Matrix multiplication(矩阵相乘)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久精品一区二区在线观看 | 国产靠逼视频 | 羞羞软件| 国产精品女教师 | 久久久久人妻精品一区二区三区 | 男人的天堂网av | 精品国产va久久久久久久 | 蜜臀少妇久久久久久久高潮 | 狠狠干精品 | 爱爱视频一区 | 免费看黄色一级大片 | 国产福利小视频在线观看 | 草草影院av | 香蕉伊思人视频 | 国产一区二区三区91 | 日韩精品一区二区三区四区 | 中文字幕第一页在线播放 | 人妻丰满熟妇av无码区不卡 | 日韩一级精品 | 久久久久亚洲av无码a片 | 国产黄色在线播放 | 国产午夜啪啪 | 久久精品久久久久久 | 久久久国际精品 | www,久久久| 久久久久久18 | 泷泽萝拉在线播放 | av福利片 | 成人a√ | 大屁股白浆一区二区三区 | 免费a级片视频 | 一本视频在线 | 侵犯女教师一区二区三区 | 伊人久操视频 | 亚洲香蕉网站 | 欧美精品第一页 | 国产视频一二三区 | 午夜免费激情视频 | 涩涩视频网站在线观看 | 午夜av网站 | 一二三区免费视频 | 男生和女生一起差差差很痛的视频 | 影音先锋人妻啪啪av资源网站 | 国产精品影音先锋 | 公车乳尖揉捏酥软呻吟 | 天天摸天天干 | 国产女人被狂躁到高潮小说 | 色婷婷av777 麻豆传媒网站 | av日韩高清 | 国产人妻精品午夜福利免费 | 国内精品在线播放 | 国产成人无码精品久久 | 日韩久久精品视频 | 美女mm131爽爽爽免费动视频 | 亚洲妇女体内精汇编 | 日韩久久中文字幕 | 精品伦精品一区二区三区视频 | 欧美一区二区三区免费在线观看 | 四虎精品成人免费网站 | www久久com | 伊人动漫 | 国产精品suv一区二区69 | av网站地址 | 青青草手机视频 | 亚洲卡一 | 婷婷玖玖| 波多野结衣爱爱 | 国产免费二区 | 欧美五月 | 色播网址| 欧美操操| 99久草 | 日韩在线视频你懂的 | 久久成人在线观看 | 婷婷中文在线 | 日本大尺度电影免费观看全集中文版 | 欧美色图13p | 美女性生活视频 | 国产精美视频 | 米奇影音| 中文字幕黄色 | av在线在线| 久热最新视频 | 欧美精品1区2区 | 狠久久 | 欧美成人精品一区二区男人看 | 91偷拍一区二区三区精品 | 亚洲精选久久 | 少妇又色又爽 | 性色视频 | www.午夜激情 | 黄色小视频免费网站 | 无码人妻丰满熟妇区毛片蜜桃精品 | 黄色美女片| 欧美干干| 日日操狠狠干 | 中文字幕一区二区不卡 | 浮生影视在线观看免费 | 天堂资源av |