首页 > 代码库 > SCU 4440 Rectangle (思维+暴力)

SCU 4440 Rectangle (思维+暴力)

题意:给你一个n*m的方格,给定周长,求在不大于这个周长的情况下,问有多少个矩形 

思路:固定一边枚举边的长度,然后根据等差数列计算

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long
using namespace std;

int main()
{
    ll n,m,k;
    while(scanf("%lld %lld %lld",&n,&m,&k)!=-1)
    {
        if(k<4) cout<<"0"<<endl;
        else
        {
            if(n>m) swap(n,m);
            ll ans = 0;
            for(ll x=1;x<=n;x++)
            {
                ll y=min(m,(k-2*x)/2);
                if(y<0) break;
                ans=ans+((n-x+1)*(2*m-y+1)*y)/2;
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}

 

SCU 4440 Rectangle (思维+暴力)