Poj 3364 Black and white painting

Black and white painting
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2458 Accepted: 1678

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 nm 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

开始看这题有点蒙,画了各种图,没思路。回过头来重新读题。就来思路了。我把8*8格子缩为1*1格子,该格子白色就符合,黑色就不符合。9*9变成2*2....类推得n*m即为(n-8+1)*(m-8+1)的格子,然后找格子有多少白色的,就有多少棋盘了。

代码:

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n,m,i;
    while(scanf("%d%d%d",&n,&m,&i))
    {
        if(n == 0 && m == 0 && i == 0)
            break;
        n = n-7;
        m = m-7;
        if((n*m)%2 == 0)
        {
            cout << (n*m)/2 <<endl;
        }
        else
        {
            if(i == 1)
            {
                cout << (n*m)/2 +1 <<endl;
            }
            if(i == 0)
            {
                cout << (n*m)/2 <<endl;
            }
        }
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值