[斯坦福开放课程.编程方法].作业.1-4.Karel将Beeper放在中间

Assignments.1-4.MidpointFindingKarel.Programme Ethodology.Stanford Open Course.

Problem 4

As an exercise in solving algorithmic problems, program Karel to place a single beeper at

the center of 1st Street. For example, if Karel starts in the world

it should end with Karel standing on a beeper in the following position:

 

Note that the final configuration of the world should have only a single beeper at the

midpoint of 1st Street. Along the way, Karel is allowed to place additional beepers

wherever it wants to, but must pick them all up again before it finishes.

In solving this problem, you may count on the following facts about the world:

• Karel starts at 1st Avenue and 1st Street, facing east, with an infinite number of

beepers in its bag.

• The initial state of the world includes no interior walls or beepers.

• The world need not be square, but you may assume that it is at least as tall as it is wide.

Your program, moreover, can assume the following simplifications:

• If the width of the world is odd, Karel must put the beeper in the center square. If the

width is even, Karel may drop the beeper on either of the two center squares.

• It does not matter which direction Karel is facing at the end of the run.

There are many different algorithms you can use to solve this problem. The interesting

part of this assignment is to come up with a strategy that works.

 

 

把Beeper放在Street 1的中央:



把Beeper放在整个方形街区的中央:
 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值