zoukankan      html  css  js  c++  java
  • HDU 4920 Matrix multiplication

    Matrix multiplication

    Time Limit: 2000ms
    Memory Limit: 131072KB
    This problem will be judged on HDU. Original ID: 4920
    64-bit integer IO format: %I64d      Java class name: Main
     
    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

    Source

     
    解题:利用cache进行加速。。
     
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 typedef long long LL;
     4 const int maxn = 810;
     5 int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
     6 int main() {
     7     int n;
     8     while(~scanf("%d",&n)) {
     9         memset(c,0,sizeof c);
    10         for(int i = 0; i < n; ++i)
    11             for(int j = 0; j < n; ++j) {
    12                 scanf("%d",a[i]+j);
    13                 a[i][j] %= 3;
    14             }
    15         for(int i = 0; i < n; ++i)
    16             for(int j = 0; j < n; ++j) {
    17                 scanf("%d",b[i]+j);
    18                 b[i][j] %= 3;
    19             }
    20         for(int i = 0; i < n; ++i)
    21             for(int k = 0; k < n; ++k)
    22                 for(int j = 0; j < n; ++j)
    23                     c[i][j] += a[i][k]*b[k][j];
    24         for(int i = 0; i < n; ++i) {
    25             for(int j = 0; j + 1 < n; ++j)
    26                 printf("%d ",c[i][j]%3);
    27             printf("%d
    ",c[i][n-1]%3);
    28         }
    29     }
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    redis官方网站及文档
    kafka 官网帮助文档
    elasticsearch 官方入门 及 API
    解决Maven出现Plugin execution not covered by lifecycle configuration 错误
    linux下scp用法
    Spring AOP 实现原理
    深入浅出spring IOC中三种依赖注入方式
    Servlet API 中文版
    【转】httpservlet 文章
    jsp request 对象详解
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4720299.html
Copyright © 2011-2022 走看看