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
  • 相关阅读:
    Celery ---- 分布式队列神器 ---- 入门
    如何使用Python快速制作可视化报表----pyecharts
    django 使用 可视化包-Pyechart
    git & github 快速入门
    开发效率进阶
    windows编译 obs-studio
    python 控制vbox虚拟机
    pyqt实践——从裸机到打包安装
    测试darwin calendar 服务器
    centos 搭建 darwin calendar 服务器
  • 原文地址:https://www.cnblogs.com/crackpotisback/p/4720299.html
Copyright © 2011-2022 走看看