杂码系列之 Black and white painting hdoj 1802

 /*
Black and white painting

http://acm.hdu.edu.cn/showproblem.php?pid=1802

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 308    Accepted Submission(s): 218


Problem 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
HDOJ 2007 Summer Exercise(1)

*/

/*

题意:

将8*8的棋盘嵌入一个长为n,宽为m的方块中,棋盘右下角必须是白色的;

c为0或1。0代表右下角是黑色,1代表右下角是白色;

输入 以n,m,c,均为0结束;

输出  每种情况能嵌入棋盘的个数;

 */

/*
思路 1:
把8*8格子缩为1*1格子,该格子白色就符合,黑色就不符合。
9*9变成 2*2....
类推得.....
n*m即为(n-8+1)*(m-8+1)的格子,然后找格子有多少白色的,就有多少棋盘了。
*/

/*
思路 2:
    由于棋盘的右下角的棋子颜色必须是已定下来的,白色的。而且长宽均为8,
所以右下角的棋子位置的区域是可以定下来的,
    即 (m-7)*(n-7),
   又因为棋盘颜色只有黑白两种,
所以棋子的位区域应该除以二,
   如果是以上的乘积得到偶数的话,
无论右下角是什么颜色都是除以二,但是如果是单数的话,

*/
/*AC1*/
/*
#include
#include
int main()
{
 int n,m,c;
 while(scanf("%d%d%d",&n,&m,&c),(m+n+c))
 {
  int p,q;
  p=n-7;
  q=m-7;
  if(!((p*q)&1))
    printf("%d\n",(p*q)/2);
  else
  {
   if(c)
     printf("%d\n",(p*q)/2+1);
       else
      printf("%d\n",(p*q)/2);
  }
 }
 return 0;
}
*/

#include
#include
int main()
{
 int n,m,c;
 while(scanf("%d%d%d",&n,&m,&c),(m+n+c))
 {
  int p,q;
  p=n-7;
  q=m-7;
    if((p*q)&1)
      printf("%d\n",(p*q)/2+c);
   else
    printf("%d\n",(p*q)/2);
 }
 return 0;
}

你可能感兴趣的:(杂乱,hdoj,代码)