欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

POJ3364 HDU1802 UVA11231 Black and white painting【数学】

程序员文章站 2022-05-21 18:58:12
...

Black and white painting
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2842 Accepted: 1938

Description

You are visiting the Centre Pompidou which contains a lot of modern paintings. In particular you notice one painting which consists solely of black and white squares, arranged in rows and columns like in a chess board (no two adjacent squares have the same colour). By the way, the artist did not use the tool of problem A to create the painting.

Since you are bored, you wonder how many 8 × 8 chess boards are embedded within this painting. The bottom right corner of a chess board must always be white.

Input

The input contains several test cases. Each test case consists of one line with three integers n, m and c. (8 ≤ n, m ≤ 40000), where n is the number of rows of the painting, and m is the number of columns of the painting. c is always 0 or 1, where 0 indicates that the bottom right corner of the painting is black, and 1 indicates that this corner is white.

The last test case is followed by a line containing three zeros.

Output

For each test case, print the number of chess boards embedded within the given painting.

Sample Input

8 8 0
8 8 1
9 9 1
40000 39999 0
0 0 0

Sample Output

0
1
2
799700028

Source

Ulm Local 2007

问题链接POJ3364 HDU1802 UVA11231 Black and white painting
问题简述:(略)
问题分析
    给定一个nm大小的黑白相间的棋盘(第三个参数表示右下角是黑色还是白色),问一个88黑白相间的模板(右下角为白色)有多少个匹配位置可以放置。
    模板右下角只有k=(n-7)*(m-7)的位置可能放置,而且如果k为偶数,无论棋盘右下角是黑是白可以放置的位置相同;如果k是奇数,则白比黑多1。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ3364 HDU1802 UVA11231 Black and white painting */

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n, m, c, ans;
    while(~scanf("%d%d%d", &n, &m, &c) && (n || m || c))  {
        if(n < 8 || m < 8)
            ans = 0;
        else {
            int tmp = (n - 8 + 1) * (m - 8 + 1);
            ans = c ? (tmp  + 1) / 2 : tmp / 2;
        }
        printf("%d\n", ans);
    }

    return 0;
}