官方解题报告http://blog.sina.com.cn/s/blog_a19ad7a10102uyxr.html
1 #include<cstdio> 2 #include<cctype> 3 const int M=810; 4 int a[M][M],b[M][M],c[M][M]; 5 inline int getint(){ 6 int res=0; 7 char tmp; 8 while(!isdigit(tmp=getchar())); 9 do{ 10 res=(res<<3)+(res<<1)+tmp-'0'; 11 }while(isdigit(tmp=getchar())); 12 return res; 13 } 14 int main(){ 15 int n,x,i,j,k; 16 while(~scanf("%d",&n)){ 17 for(i=0;i<n;i++){ 18 for(j=0;j<n;j++){ 19 a[i][j]=getint(); 20 a[i][j]%=3; 21 } 22 } 23 for(i=0;i<n;i++){ 24 for(j=0;j<n;j++){ 25 b[i][j]=getint(); 26 b[i][j]%=3; 27 c[i][j]=0; 28 } 29 } 30 for(k=0;k<n;k++){ 31 for(i=0;i<n;i++){ 32 if(a[i][k]){ 33 for(j=0;j<n;j++){ 34 c[i][j]+=a[i][k]*b[k][j]; 35 } 36 } 37 } 38 } 39 for(i=0;i<n;i++){ 40 for(j=0;j<n;j++){ 41 if(j) putchar(' '); 42 putchar(c[i][j]%3+'0'); 43 } 44 putchar('\n'); 45 } 46 } 47 return 0; 48 }