1. 程式人生 > >【CodeForces - 215C 】Crosses (思維,圖形題)

【CodeForces - 215C 】Crosses (思維,圖形題)

題幹:

There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j

 as (i, j).

A group of six numbers (a, b, c, d, x0, y0), where 0 ≤ a, b, c, d, is a cross, and there is a set of cells that are assigned to it. Cell (x, y) belongs to this set if at least one of two conditions are fulfilled:

  • |x0 - x| ≤ a and |y
    0 - y| ≤ b
  • |x0 - x| ≤ c and |y0 - y| ≤ d

 The picture shows the cross (0, 1, 1, 0, 2, 3) on the grid 3 × 4.

Your task is to find the number of different groups of six numbers, (a, b, c, d, x0, y0) that determine the crosses of an area equal to s, which are placed entirely on the grid. The cross is placed entirely on the grid, if any of its cells is in the range of the grid (that is for each cell (x

, y) of the cross 1 ≤ x ≤ n; 1 ≤ y ≤ mholds). The area of the cross is the number of cells it has.

Note that two crosses are considered distinct if the ordered groups of six numbers that denote them are distinct, even if these crosses coincide as sets of points.

Input

The input consists of a single line containing three integers nm and s (1 ≤ n, m ≤ 500, 1 ≤ s ≤ n·m). The integers are separated by a space.

Output

Print a single integer — the number of distinct groups of six integers that denote crosses with area s and that are fully placed on the n × m grid.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

2 2 1

Output

4

Input

3 4 5

Output

4

Note

In the first sample the sought groups of six numbers are: (0, 0, 0, 0, 1, 1), (0, 0, 0, 0, 1, 2), (0, 0, 0, 0, 2, 1), (0, 0, 0, 0, 2, 2). 

In the second sample the sought groups of six numbers are: (0, 1, 1, 0, 2, 2), (0, 1, 1, 0, 2, 3), (1, 0, 0, 1, 2, 2), (1, 0, 0, 1, 2, 3).

題目大意:

   給你兩個關係,(可以認為代表兩個矩形,這很關鍵)。問你滿足條件的六元組個數有多少個?

解題報告:

   不錯的一個思維題。反正讓我自己想是想不出來的、、、

AC程式碼:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
int n,m,s,r;
__int64 f(int h,int w) {
	return (n - h + 1) * (m - w + 1 );
}
__int64 ans;
int main() 
{
	scanf("%d%d%d",&n,&m,&s);
	for(int i = 1; i <= n; i += 2) {
		for(int j = 1; j <= m; j += 2) {
			r=s-i*j;
			if(r == 0) {
				ans +=((i + 1) * (j + 1) / 2 - 1) * f(i,j);
			}
			else if(r > 0) {
				for(int k = 1; k < j; k += 2) {
					if((r%2==0) &&(r/2)%k == 0 && i + r/k <= n) ans += 2*f(i+r/k,j);
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}

總結:根據gy學長給的公式,,最後那個if判斷那裡可以直接寫成if(r%(2*k) == 0 && i+r/k <= n)。

官方題解:

#include <cstdio>
int n,m,s,r;
//2 equations represents 2 rectangles!!!
//so we enumerate one rectangle's hight and width
 
//how many rectangle with h and m are there in the big given rectangle
__int64 f(int h,int w){ return (n - h + 1) * (m - w + 1 );}
__int64 ans;
int main(){
    scanf("%d%d%d",&n,&m,&s);
    ans = 0;
    for(int i = 1; i <= n; i += 2){//enumerate hight
        for(int j = 1; j <= m && (r = s - i * j) >= 0; j += 2){
            if(r == 0){//one rectangle is fairly enough
        //suppose (a,b) must be i,j
        //then (c,d) can have (i + 1)/2 * (j + 1)/2 choices
        //then (a,b) and (c,d) can exchange, so we * 2
        //but if(a,b) and (c,d) are the same,exchange them does not make any difference
        //that is when a = c = i, b = d = j
                ans +=( (i + 1) * (j + 1) / 2 - 1) * f(i,j);
            }else
                for(int k = 1; k < j; k += 2)
                    if(r % (2 * k) == 0 && i + r / k <= n)
                        ans += 2 * f(i + r / k, j);// (a,b) and (c,d) can exchange
        }
    }
    printf("%I64d\n",ans);
    return 0;
}