nyoj 623 A*B Problem II

A*B Problem II

时间限制:1000 ms  |  内存限制:65535 KB

难度:1

描述
ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大量的乘法都会把他搞乱,所以他想请你写个程序帮他检验一下计算结果是否正确。

输入
有多组测试数据,每行给出一组m,n,k(0<m,n,k<=50)。m,n,k表示两个矩阵的大小,其中:

矩阵A:m行n列。

矩阵B:n行k列。

接下来给出m*n个数表示矩阵A和n*k个数表示矩阵B,对于每个数s,0<=s<=1000。

当m,n,k同时为0时结束。

输出
计算两个矩阵的乘积并输出。
样例输入
2 1 3
1
2
1 2 3
2 2 3
1 2
3 4
1 0 1
0 1 0
0 0 0
样例输出
1 2 3
2 4 6
1 2 1

3 4 3

矩阵的乘法,好麻烦啊,写了好长时间,要砸键盘了

2015,5,28

#include<stdio.h>
int a[53][53],b[53][53];
int main(){
	int m,n,k,i,j,sum,v;
	while(scanf("%d%d%d",&m,&n,&k),m+n+k){
		for(i=1;i<=m;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&a[i][j]);
		for(i=1;i<=n;i++)
			for(j=1;j<=k;j++)
				scanf("%d",&b[i][j]);
		for(i=1;i<=m;i++){//第一个矩阵的行
			for(v=1;v<=k;v++){//第二个矩阵的列
				sum=0;//注意每次清0
				for(j=1;j<=n;j++)//第一个矩阵的列,和第二个矩阵的行
					sum+=a[i][j]*b[j][v];
				printf("%d ",sum);
			}
			printf("\n");
		}
	}
	return 0;
} 
时间: 2024-10-24 01:55:39

nyoj 623 A*B Problem II的相关文章

NYOJ 623 A*B ProblemII

A*B Problem II 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 ACM的C++同学有好多作业要做,最头痛莫过于线性代数了,因为每次做到矩阵相乘的时候,大量的乘法都会把他搞乱,所以他想请你写个程序帮他检验一下计算结果是否正确. 输入 有多组测试数据,每行给出一组m,n,k(0<m,n,k<=50).m,n,k表示两个矩阵的大小,其中: 矩阵A:m行n列. 矩阵B:n行k列. 接下来给出m*n个数表示矩阵A和n*k个数表示矩阵B,对于每个数s,0<

杭电1023Train Problem II

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目: Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7675    Accepted Submission(s): 4131 Problem Description As we all know the

Train Problem II 卡特兰裸题(入门题)

Train Problem II  题目大意:给你一个数n,表示有n辆火车,编号从1到n,从远方驶过来,问你有多少种出站的可能. 解题思路:模拟栈的问题而已.  卡特兰问题. 1 import java.math.*; 2 import java.util.*; 3 import java.io.*; 4 5 public class Main 6 { 7 static int MS=101; 8 public static void main(String[] args) 9 { 10 Sca

hdoj 1002 A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 242959    Accepted Submission(s): 46863 Problem Description I have a very simple problem for you. Given two integers A and B, you

【HDOJ 1002】A + B Problem II

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 238517    Accepted Submission(s): 45969 Problem Description I have a very simple problem for you. Given two integers A and B, you

HDU 1002-A + B Problem II(大数类)

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 215173    Accepted Submission(s): 41521 Problem Description I have a very simple problem for you. Given two integers A and B, yo

hdoj 1023 Train Problem II 【卡特兰】+【高精度】

题意:询问有多少种进站出站的顺序. 经典卡特兰.我对卡特兰目前的认识就是有n个1和n个-1,组成一个为2n的数列的方式有多少种.这就跟火车进站出站类似, 至于具体的卡特兰数的介绍,百度解释的很详细. 代码1(c语言): /* h(n) = h(n-1)*(4*n-2)/(n+1); */ #include <stdio.h> #include <string.h> #define M 110 int s[M][M] = {0}, b[M]; void init(){ s[1][0]

A + B Problem II(杭电1002)

/*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input contains an integer T(1<=T<=20) which means the number of test case

HDU 1002 A + B Problem II(大整数相加)

A + B Problem II Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. Input The first line of the input c