Python中计算国际象棋棋盘的最小切割次数,使其不分成两部分


假设我们有一个A x B的国际象棋棋盘(矩阵),我们必须计算在这个棋盘上可以进行的最大切割次数,以使棋盘不会分成两部分。

因此,如果输入是A = 2,B = 4,

则输出为3

为了解决这个问题,我们将遵循以下步骤:

  • res := 0
  • res := (M - 1) * (N - 1)
  • 返回 res

示例

让我们看看下面的实现,以便更好地理解:

 在线演示

def max_cuts_count(M, N):
   res = 0
   res = (M - 1) * (N - 1)
   return res
M, N = 2, 4
Cuts = max_cuts_count(M, N)
print(Cuts)

输入

2,4

Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.

输出

3

更新于:2020年8月27日

64 次浏览

开启你的职业生涯

完成课程获得认证

开始学习
广告