码迷,mamicode.com
首页 > 其他好文 > 详细

HDU4920 Matrix multiplication 矩阵

时间:2017-08-05 09:47:26      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:getch   stdin   etc   hdu   class   pop   math   vector   long   

不要问窝 为什么过了> <

窝也不造为什么就过了 

说是%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?'\n':' ');
            }
    }
    return 0;
}


HDU4920 Matrix multiplication 矩阵

标签:getch   stdin   etc   hdu   class   pop   math   vector   long   

原文地址:http://www.cnblogs.com/yfceshi/p/7288927.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!