弱校联萌十一大决战之强力热身 E. Rectangle (规律)

E. Rectangle
Time Limit: 1000msMemory Limit: 65536KB 64-bit integer IO format: %lld Java class name: Main
Submit Status
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 (1≤n,m≤5⋅104,0≤k≤109).
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




解析:枚举矩形的长h,然后它在h的方向上就有n-h+1种放法,同时宽的最大值w即为k/2 - h,对于每个0~w的宽度wi,它在w方向上的放法有m-wi+1种,求和即为所求方案数

PS:用printf输出long long的结果,你看到的并不是你想要的,竟然是个负数。但是cout还是没问题的



AC代码:

#include <bits/stdc++.h>
using namespace std;

int main(){
    #ifdef sxk
        freopen("in.txt", "r", stdin);
    #endif // sxk

    long long n, m, k;
    while(cin>>n>>m>>k){
        k /= 2;
        long long ans = 0;
        for(int h=1; h<=n; h++){
            int w = k - h;
            if(w <= 0) break;
            if(w > m) w = m;
            ans += (n - h + 1) * (m + m-w+1)*w/2;    //对于每个h,在h方向上n-h+1种,在w方向上枚举wi求和为(m + m-w+1) * w / 2种
        }
        cout<<ans<<endl;
    }
    return 0;
}

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值