A. Domino piling
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
-
Each domino completely covers two squares.
-
No two dominoes overlap.
-
Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input
In a single line you are given two integers M and N — board sizes in squares (1 ≤ M ≤ N ≤ 16).
Output
Output one number — the maximal number of dominoes, which can be placed.
Examples
inputCopy
2 4
outputCopy
4
inputCopy
3 3
outputCopy
4
n、m范围到16,若是题难没规律可以打表,这题的1 * 2简单些,但凡原矩形有一条边为偶数,就能全部用上,两条边都为奇数只有一格用不到,这样一来答案都是:n * m / 2
#include <iostream>
using namespace std;
int main()
{
int n, m;
while(cin >> n >> m)
cout << n * m / 2 << '\n';
return 0;
}