zoukankan      html  css  js  c++  java
  • HDU4920 Matrix multiplication 矩阵

    不要问窝 为什么过了> <

    窝也不造为什么就过了 

    说是%3变成稀疏矩阵 

    可是随便YY个案例都会超时。。

    看来数据是随机的诶

    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <limits.h>
    #include <malloc.h>
    #include <ctype.h>
    #include <math.h>
    #include <string>
    #include<iostream>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    #define MAXN 100*111
    #include <queue>
    #include <vector>
    #define IN freopen("in.txt","r",stdin);
    #define OUT freopen("out.txt","w",stdout);
    int Scan()
    {
        int x;
        char c;
        while((c=getchar())<'0' || c>'9') ;
        x=c-'0' ;
        while((c=getchar())>='0' && c<='9')
            x+=c-'0';
        x%=3 ;
        return x;
    }
    int a[888][880],b[880][880],c[880][880];
    int main()
    {
        int n;
        IN;
        while(scanf("%d",&n)!=EOF)
        {
            memset(c,0,sizeof(c));
            for(int i=0; i<n; i++)
                for(int j=0; j<n; j++)
                    a[i][j]=Scan();
            for(int i=0; i<n; i++)
            {
                for(int j=0; j<n; j++)
                {
                    b[i][j]=Scan();
                }
            }
            for(int i=0; i<n; i++)
                for(int k=0; k<n; k++)
                {
                    if(a[i][k]==1)
                        for (int j=0; j<n ; j++)
                            c[i][j]+=b[k][j];
                    else if(a[i][k]==2)
                        for(int j=0; j<n; j++ )
                            c[i][j]+=(b[k][j]<<1);
                }
            for(int i=0; i<n; i++)
                for(int j=0; j<n; j++)
                {
                    printf("%d%c",c[i][j]%3,j==n-1?'
    ':' ');
                }
        }
        return 0;
    }
    


  • 相关阅读:
    this.props.children 踩坑
    3.webpack配置
    2.项目初始化配置
    1项目库的建立
    Idea-代码背景设置
    SpringBoot+nacos-环境切换-配置文件
    Docker-镜像地址无法访问
    端口-映射、开放、定义
    Linux-命令
    Nginx-命令
  • 原文地址:https://www.cnblogs.com/yfceshi/p/7288927.html
Copyright © 2011-2022 走看看