HDU4920 inappropriate violence
Original question http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 4920
Matrix multiplication
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission (s): 848 Accepted Submission (s): 339
Problem DescriptionGiven 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.
InputThe 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. 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 ).
OutputFor each tests:
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
AuthorXiaoxu Guo (ftiasch)
Source2014 Multi-University Training Contest 5
RecommendWe have carefully selected several similar problems for you: 4919 4918 4917 4916 4915
// At the beginning, I thought what advanced algorithms were used for this question. Later, I found that many people have passed the process. It is probably a little tricky. // first of all. Multiplication takes more time than addition. So we can avoid multiplication and try to optimize it. // After this question, it is found that C ++ runs faster than G ++, and the same code is nearly 0.4 seconds behind it. During the competition, it was due to the fact that I had handed in G ++ T for many times. // finally, I said, cool, although the violence was not omnipotent. However, violence without tips is absolutely unacceptable. # Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define Max 800 + 5int a [Max] [Max]; int B [Max] [Max]; int c [Max] [Max]; int main () {int n, I, j; while (~ Scanf ("% d", & n) {memset (a, 0, sizeof (a); memset (B, 0, sizeof (B); memset (c, 0, sizeof (c); for (I = 0; I