Hdu2524 (calculate the number of rectangles, questions ...), Hdu2524 rectangle
Hdu 2524N-brute force solution and table Creation
Time Limit:1000 MS
Memory Limit:32768KB
64bit IO Format:% I64d & % I64u
Description
A grid with a height of n and a width of m columns is provided. The number of rectangles in the grid is calculated. The grid with a height of 2 and a width of 4 is displayed.
Input
Input a t in the first line, indicating that there is a t group of data, and then input n, m in each line, indicating the height and width of the grid respectively (n <100, m <100 ).
Output
The number of rectangles in the output grid of each row.
Sample Input
21 22 4
Sample Output
330
It seems that the solution to this question is violent, but it is good to find its mathematical law.
Number of rectangles = n * (n + 1)/2 * m * (m + 1)/2
AC code:
#include<iostream>using namespace std;int main(){ int t,n,m,s; cin>>t; while(t--) { cin>>n>>m; s=n*(n+1)/2*m*(m+1)/2; cout<<s<<endl; } return 0;}