美高梅网络游戏网址URAL 1876 Centipede’s Morning(数学)

从前在英国,有只刚学会直立起来走路的猩猩,它的右脚是正常的,健康的。它的左脚却先天不足,不但有点瘸,关节还有毛病,由于还不适应两只脚走路,行动起来,有时不免要碰碰右脚。为这一点,两只脚老是吵架。
右脚说:你这废物蛋!白活了,还不如没有你l
左脚说:就你好!我不如你!你不会好好帮助我、配合我吗!你就没有缺点!
右脚说:笑话!我是右脚The right one,天然正确的一个。
猩猩被两只脚吵得烦透了,决心要解决这个问题。心想:右脚一The right
one一当然是对的,于是请医生把它的在娘胎里就注定要倒霉的左脚锯掉。
讨厌的左脚锯掉了,疼痛过去了,吵闹没有了,伤口也慢慢愈合了!当猩猩再想直立起来走路的时候,它才发现,这右脚虽然是天然正确、完美无缺的,但一只脚怎么也走不了路。它只好又趴在地上,用三只脚跳和爬。选自1980年2月17日《羊城晚报》[注]The
right one,英语,意即右边的一个,也可译为正确的一个。这里作双关语用。

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 ≤ ab ≤ 100).

Output

Output the number of seconds the centipede will need for shoeing in the
worst case.

 

题目大意:

思路:挺有意思的一道题目。

考虑最快情况,第一种最坏情况很明显,就是把右脚的鞋子全穿一遍,然后再穿完左脚,耗时2b+40。

第二种情况,先穿完左脚,再穿完右脚?不不不,还有更糟糕的情况,先给右脚穿好39只,耗时39*2,然后给左脚穿完鞋子,耗时40,再给右脚最后一只脚穿,把剩下的左脚鞋子都上一遍,耗时2(a-40),然后穿上,耗时1。总耗时39*2+2(a-40)+1。

 

代码(0.046S):

美高梅网络游戏网址 1美高梅网络游戏网址 2

1 a, b = map(int, raw_input().split(' '))
2 print max(2 * b + 40, 39 * 2 + 40 + 2 * (a - 40) + 1)

View Code