程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> random-Centipedes Morning

random-Centipedes Morning

編輯:編程解疑
Centipede's Morning

A centipede has 40 left feet and 40 right feet. It keeps a left slippers and b right slippers under its bed. Every morning the centipede puts on the slippers. It pokes its first left foot under the bed and puts on a random slipper, doing it in one second. If the slipper is left, the centipede passes to shoeing the second left foot. Otherwise, it takes off the slipper and puts it on any unshod right foot, spending one more second, so that it takes two seconds altogether to put on such a slipper. If there are no unshod right feet, the centipede throws the slipper to a corner of the room, also in one second, so that two seconds are spent altogether for this slipper. The process is continued until all the left feet are in left slippers. Then the centipede starts shoeing its right feet until all of them are shod.
Today the centipede has got out of bed on the wrong side, so it is preparing for the worst. How many seconds will it need for shoeing?
Input
The only line contains the integers a and b (40 ≤ a, b ≤ 100).
Output
Output the number of seconds the centipede will need for shoeing in the worst case.
Sample
input output
40 40
120

最佳回答:


http://blog.csdn.net/u013446688/article/details/44117757

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved