⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toj_2909.cpp

📁 Tianjin University Online Judge 的80多道题目 .
💻 CPP
字号:
/*2909.   Black and white painting Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 29   Accepted Runs: 23You 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.InputThe 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.OutputFor each test case, print the number of chess boards embedded within the given painting.Sample Input8 8 08 8 19 9 140000 39999 00 0 0Sample Output012799700028Source: University of Ulm Local Contest 2007*/#include<cstdio>int addLine( int num , int c ){  if ( num % 2 == 0 )    return num / 2 - 4 + c;  else    return ( num - 7 ) / 2;}  int find( int n , int m , int c ){  int addition , additionM , additionN;  if ( n <= 8 && m <= 8 )    {      if ( c == 0 )	{	  return 0;	}      else	{	  return 1;	}    }  else if ( n <= 8 && m > 8 )    {      return ( n , m - 1 , 1 - c ) + addLine( m , c );    }  else if ( m <= 8 && n > 8 )    {      return ( n - 1 , m , 1 - c ) + addLine( n , c );    }  else if ( m > 8 && n > 8 )    {      addition = addLine( m , c ) + addLine( n , c ) - c;      return( n - 1 , m - 1 , c ) + addition;    }}int main(){  int n , m , c , result;  while ( scanf( "%d%d%d"  ,&n , &m , &c ) != EOF && ( n != 0 || m != 0 || c != 0 ) )    {      result = find( n , m , c );      printf( "%d\n" , result );    }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -