hdu 4364 Matrix operation

无奈了,只是用cout输出了两个回车,结果一个超时,一个竟然只用了100+ms,很无语~~

题意:

已知矩阵A:2 3 1 1
1 2 3 1
1 1 2 3
3 1 1 2
已知矩阵B(8位16进制表示)。
求A*B得到的新矩阵。

思路:呃,这题中的加法是定义为异或运算的,没读题,只是听XH说了一下题意就开始做了,悲剧的是怎么都不对,然后又问了一下XH题意。。。。。

代码:

View Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#define  N 4
using namespace std ;

int d[N][N] = { 2 , 3 , 1 , 1 ,
                1 , 2 , 3 , 1 ,
                1 , 1 , 2 , 3 ,
                3 , 1 , 1 , 2
                };

int p[N][N] ;

int cal ( int x , int y )
{
    int i , sum = 0 ;

    for ( i = 0 ; i < 4 ; i++ )
    {
        if ( d[x][i] != 2 )
        sum ^= p[i][y] ;
        if ( d[x][i] != 1 )
        {
            if ( p[i][y] & 128 )
            sum ^= 27 ;
            sum ^= (( p[i][y] << 1 ) & 255 );
        }
    }
    return sum ;
}

int main()
{
    int cas , i , j , x , y , tem ;

    scanf( "%d" , &cas );
    while ( cas-- )
    {
        for ( i = 0 ; i < 4 ; i++ )
        for ( j = 0 ; j < 4 ; j++ )
        {
            scanf( "%1x%1x" , &x , &y );
            tem = ( x << 4 ) + y ;
            p[i][j] = tem ;
        }

        for ( i = 0 ; i < 4 ; i++ )
        {
            for ( j = 0 ; j < 4 ; j++ )
            {
                tem = cal ( i , j );
                if ( !j )
                {
                    printf ( "%X%X" , tem >> 4 , tem & 15 );
                }
                else
                {
                    printf ( " %X%X" , tem >> 4 , tem & 15 );
                }
            }
            printf ( "\n" );
        }
        if ( cas )
        printf ( "\n" );
    }
    return 0 ;
}
原文地址:https://www.cnblogs.com/misty1/p/2639723.html