1. 程式人生 > >HDU 4920: Matrix multiplication

HDU 4920: Matrix multiplication

style row continue link amp round acm cati 5.0


///@date 9/26/2017
///@author Sycamore
///@link http://acm.hdu.edu.cn/showproblem.php?pid=4920
#include<bits/stdc++.h>
using namespace std;

int main()
{

ios::sync_with_stdio(false);
//cin.tie(nullptr);
int n;
while(cin>>n)
{
vector<vector<int>> A(n,vector<int>(n)),B(n,vector<int
>(n)),C(n,vector<int>(n));
for(auto &row:A)
for(auto &el:row)
{
cin>>el;
el%=3;
}

for(auto &row:B)
for(auto &el:row)
{
cin>>el;
el%=3;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(A[i][j])
for(int k=0;k<n;k++)
C[i][k]+=A[i][j]*B[j][k];
else continue;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
cout<<
C[i][j]%3<<(j==n-1?\n:‘ ‘);
}
}

}

HDU 4920: Matrix multiplication