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:

  1. Each domino completely covers two squares.

  2. No two dominoes overlap.

  3. 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;
}
全部评论

相关推荐

走不到的路就这样算了吗:大佬硬气
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务