Go语言实现Playing on a chessboard

描述

With a friend we used to play the following game on a chessboard (8, rows, 8 columns). On the first row at the bottom we put numbers:
1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9
On row 2 (2nd row from the bottom) we have:
1/3, 2/4, 3/5, 4/6, 5/7, 6/8, 7/9, 8/10
On row 3:
1/4, 2/5, 3/6, 4/7, 5/8, 6/9, 7/10, 8/11
until last row:
1/9, 2/10, 3/11, 4/12, 5/13, 6/14, 7/15, 8/16
When all numbers are on the chessboard each in turn we toss a coin. The one who get “head” wins and the other gives him, in dollars, the sum of the numbers on the chessboard. We play for fun, the dollars come from a monopoly game!
How much can I (or my friend) win or loses for each game if the chessboard has n rows and n columns? Add all of the fractional values on an n by n sized board and give the answer as a simplified fraction.

分析

观察:只有1行1列时,结果为1/2;2行2列时,结果为2,即4/2;3行3列时,结果为9/2;4行4列时,结果为8,即16/2。以此类推,得到结果为f(n) = n 2 / 2 n^2 / 2 n2/2

实现

func Game(n int) []int {
    if n % 2 == 0 {
      return []int{ n * n / 2 }
    }
    return []int{ n * n, 2 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值