【规律】Black and white painting

描述

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.

输入

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.

输出

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

样例输入

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

样例输出

0
1
2
799700028

分析:
考虑棋盘右下角区域(借鉴TZOJ1108讨论版。)
代码:
#include
using namespace std;
int main()
{
int n,m,c;
while(cin>>n>>m>>c)
{
if (!m&&!n&&!c) break;
int p=n-7,q=m-7;
if ((pq)%2==1)
{
printf("%d\n",(p
q)/2+c);
}
else
{
printf("%d\n",(p*q)/2);
}
}
return 0;
}

你可能感兴趣的:(C语言学习)