题目:
给你一个高为n ,宽为m列的网格,计算出这个网格中有多少个矩形,下图为高为2,宽为4的网格.
Input
第一行输入一个t, 表示有t组数据,然后每行输入n,m,分别表示网格的高和宽 ( n < 100 , m < 100).
Output
每行输出网格中有多少个矩形.
Sample Input
2 1 2 2 4
Sample Output
3 30
思路:
这就是一道找规律的题;
代码如下:
JAVA:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int n=input.nextInt();
while(n>0) {
n--;
int a=input.nextInt();
int b=input.nextInt();
int s=(int)a*(a+1)*b*(b+1)/4;
System.out.println(s);
}
}
}
C++:
#include<stdio.h>
int main()
{
int t,s;
scanf("%d",&t);
while(t--)
{
int m,n;
scanf("%d%d",&m,&n);
s=m*(m+1)*n*(n+1)/4;
printf("%d\n",s);
}
return 0;
}