码迷,mamicode.com
首页 > 其他好文 > 详细

hdu2524 (水题。。。)

时间:2015-07-27 22:51:29      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

 

               hdu 2524

N - 暴力求解、打表

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
 

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
 

看似这道题解决方法是暴力,打表,但是其实找到其数学规律就好

矩形个数=n*(n+1)/2*m*(m+1)/2

 

AC代码:

#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;
}

 

hdu2524 (水题。。。)

标签:

原文地址:http://www.cnblogs.com/hfc-xx/p/4681338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!