Rectangle

Rectangle

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format:  %lld      Java class name: Main
 
frog has a piece of paper divided into  n rows and m columns. Today, she would like to draw a rectangle whose perimeter is not greater than k.
 
 
There are  8 (out of 9) ways when n=m=2,k=6
 
Find the number of ways of drawing.
 

Input

The input consists of multiple tests. For each test:
 
The first line contains  3 integer n,m,k (1n,m5104,0k109).
 

Output

For each test, write  1 integer which denotes the number of ways of drawing.
 

Sample Input

2 2 6
1 1 0
50000 50000 1000000000

Sample Output

8
0
1562562500625000000
有技巧的暴力搜索方法:
    设总方格长和宽分别为n,m,一个长为i,宽为j(j 可以大于i,这里只是为了与总方格相对应)的矩形,可以找到有(n-i+1)*(m-j+1)个这样的矩形。
    并且, i <= min(n,k-1), 取过i后,j <= min(m,k-i);有i = (1 ~ min(n,k-1)),j = (1~min(m,k-i));所以可以通过枚举i,并且由于j的值符合等差级数,可以通过“首项加末项乘以项数除以二”快速求得j。
    所有,sum[i] = (n-i+1),sum[j] = ( (m-1+1)+(m-j+1) ) * j / 2 ; ans += sum[i]*sum[j],即得。
 
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long//BNUOJ似乎不识别__int64;
using namespace std;
int main(){
    ll n,m,k;
    while(~scanf("%I64d%I64d%I64d",&n,&m,&k)){
        k /= 2;
        ll ans = 0;
        ll nn = min(n,k-1);
        for(ll i = 1; i <= nn; i++){
            ll j = min(m,k - i);
            ans += (n - i + 1)*(m + m - j + 1)*j/2;
        }
        cout<<ans<<endl;//printf("%I64d\n",ans); is WA ,I don't konw why!
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/ACMessi/p/4852668.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值