?? toj_2909.cpp
字號(hào):
/*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;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -