弱校(国庆) Rectangle

E. Rectangle

Time Limit: 1000ms
Memory 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  ( 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
Submit  Status

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
#define N 50000 + 10
#define LL long long
#define INF 0x3f3f3f3f

LL n, m, k;

int main()
{
    while(~scanf("%lld%lld%lld", &n, &m, &k))
    {
        LL ans = 0;
        LL r, c;
        k >>= 1;
        LL mr = min(n, k - 1);

        for(r = 1; r <= mr; r++)
        {
            c = min(m, k - r);
            ans += (n - r + 1) * ((m + 1) * c - c * (c + 1) / 2);
        }
        printf("%lld\n", ans);
        //cout << ans << endl;
    }
    return 0;
}

/*
2 2 6
1 1 0
50000 50000 1000000000
*/


你可能感兴趣的:(ACM)