Codeforces习题 50A Domino piling

发布于 / 技术 / 0 条评论

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.

阅读这道题目,首先会提供给我们一个M × N的矩形,之后会提供给我们无限量的2 × 1的多米诺骨牌。题目要求我们输出在这个矩形内可以放置多少枚骨牌。题目会提供两个输入,分别为M和N,两个变量处于1和16之间,要求输出骨牌的数量。

所以这个题目非常简单,首先我们将M和N相乘求出背板的体积,之后用这个体积除以2,就能得出骨牌的数量了。

我们只需要三行代码就能解决问题。

SQUARES_PARA=input().split(' ')
SQUARES_AREA=int(SQUARES_PARA[0])*int(SQUARES_PARA[1])
print(int(SQUARES_AREA/2))
ProblemLangVerdictTimeMemory
50A – 14Python 3Happy New Year!218 ms20 KB
本网站在未特殊说明的情况下采用知识共享署名-非商业性使用-相同方式共享 3.0 协议进行许可。
<-数据丢失->