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.

题目大意:http://www.nocow.cn/index.php/Translate:URAL/1876(中文题意)

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

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

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

代码(0.046S):

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

URAL 1876 Centipede's Morning(数学)的更多相关文章

  1. URAL 1876 Centipede's Morning

    1876. Centipede's Morning Time limit: 0.5 secondMemory limit: 64 MB A centipede has 40 left feet and ...

  2. URAL 1725. Sold Out!(数学啊 )

    题目链接:space=1&num=1725" target="_blank">http://acm.timus.ru/problem.aspx?space= ...

  3. URAL 1962 In Chinese Restaurant 数学

    In Chinese Restaurant 题目连接: http://acm.hust.edu.cn/vjudge/contest/123332#problem/B Description When ...

  4. URAL 1984. Dummy Guy(数学啊)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1984 1984. Dummy Guy Time limit: 0.5 second Me ...

  5. URAL 1823. Ideal Gas(数学啊 )

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time limit: 0.5 second Me ...

  6. ES : 软件工程学的复杂度理论及物理学解释

    系统论里面总是有一些通用的专业术语 比如复杂度.熵.焓,复杂度专门独立出来,成为复杂度理论 文章摘抄于:<非线性动力学> 刘秉政 编著  5.5 复杂性及其测度 热力学的几个专业术语 熵. ...

  7. URAL 1820. Ural Steaks(数学啊 )

    题目链接:space=1&num=1820" target="_blank">http://acm.timus.ru/problem.aspx? space ...

  8. ural 2029 Towers of Hanoi Strike Back (数学找规律)

    ural 2029 Towers of Hanoi Strike Back 链接:http://acm.timus.ru/problem.aspx?space=1&num=2029 题意:汉诺 ...

  9. ural 2032 Conspiracy Theory and Rebranding (数学水题)

    ural 2032  Conspiracy Theory and Rebranding 链接:http://acm.timus.ru/problem.aspx?space=1&num=2032 ...

随机推荐

  1. jira-cli,api,git,jenkins--version.txt

    cd ${WORKSPACE}/trunk/src/main/webapp/html/ echo $version | sed -e "s/X/${BUILD_NUMBER}/g" ...

  2. JavaSE的知识

    一 SE的知识体系: java基础: 一基础语法 8个基本数据类型-->8个包装类 数据类型转换: 自动转换(从小到大) 强制转换(从大到小) 注意:int 和char 分支与判断: if(){ ...

  3. android 5.0 (lollipop)源码编译环境搭建(Mac OS X)

    硬件环境:MacBook Pro Retina, 13-inch, Late 2013 处理器  2.4 GHz Intel Core i5 内存  8 GB 1600 MHz DDR3 硬盘60G以 ...

  4. android 资源ID

    在编译的时候,AAPT会扫描你所定义的所有资源(在不同文件中定义的以及单独的资源文件),然后给它们指定不同的资源ID.资源ID 是一个32bit的数字,格式是PPTTNNNN , PP代表资源所属的包 ...

  5. 101个LINQ示例,包含几乎全部操作

    Restriction Operators Where - Simple public void Linq1() { , , , , , , , , , }; var lowNums = from n ...

  6. Marriage Match IV---hdu3416(spfa + Dinic)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3416 有一个有向图,n个点,m条边,给一个起点和终点,求出从起点到终点的最短路共有几条,每 ...

  7. JS之mouseover和mouseenter

    mouseenter事件只会触发一次,触发对象是注册对象或者注册对象的子元素 mouseover事件可以触发多次,触发对象是注册对象或者注册对象的子元素 <!DOCTYPE html> & ...

  8. 解决调用context.Session["NAME"]时总出现Object reference not set to an instance of an object.异常的方法

    if (context.Session != null) { }

  9. 【转】Android各种Adapter的用法

    转自:http://my.oschina.net/u/658933/blog/372151 Android各种Adapter的用法 发表于5个月前(2015-01-27 10:56)   阅读(143 ...

  10. background-image中url找不到路径,背景图像无法显示

    <div id="body_left_secend_1">                        <img src="~/Images/imag ...