SCU 4440 Rectangle (2015四川省省赛E题)

给一个n*m的方格,求周长小于等于k的矩形有多少个。
简单的思考题。
代码:

//author: CHC
//First Edit Time: 2015-06-23 13:01
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const LL LL_INF=numeric_limits<LL>::max();
LL n,m,k;
int main()
{
    //printf("%lld\n",LL_INF);
    while(~scanf("%lld%lld%lld",&n,&m,&k)){
        LL ans=0;
        for(LL x=1;x<=n;x++){
            LL tmax=(k-2*x)/2;
            if(tmax>0){
                if(tmax>=m)tmax=m;
                if(tmax%2==0){
                    ans+=(n-x+1)*(m+m-tmax+1)*(tmax/2);
                }
                else {
                    ans+=(n-x+1)*((m+m-tmax+1)/2)*tmax;
                }
                //ans+=(n-x+1)*((m+m-tmax+1)*tmax/2);
                //printf("%lld\n",ans);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

你可能感兴趣的:(SCU 4440 Rectangle (2015四川省省赛E题))