Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5994 Accepted Submission(s): 4621
Problem Description
给你一个高为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
Source
HDU 2008-10 Programming Contest
就是简单的找规律的题,找到了就好做。
代码如下:
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int u;
int h,w;
scanf ("%d",&u);
long long ans;
while (u--)
{
scanf ("%d %d",&h,&w);
ans = 0;
for (int i = 1 ; i <= w ; i++)
{
for (int j = 1 ; j <= h ; j++)
{
if (i == j)
ans += (w-i+1)*(h-j+1);
else
ans += (w-i+1)*(h-j+1);
}
}
printf ("%lld\n",ans);
}
return 0;
}