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):

  1. a, b = map(int, raw_input().split(' '))
  2. 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. UI auto test

    java.home/lib/security/java.policy (Solaris/Linux) http://www.cnblogs.com/richaaaard/p/5091059.html ...

  2. 《黑客大曝光》实践部分——sql注入(7/8)

    SQL注入实践 由于<黑客大曝光>中涉及到形形色色的攻击方式,从软件到硬件,甚至还有物理锁的开锁教程,当中的很多教程很有趣,但是我没有相关的环境,实践起来不好操作,比如说,查点扫描我还可以 ...

  3. insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a=10001

    insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a ...

  4. __proto__和protaotype的区分

    直接看这样一个例子. var XXX = function(){}; var p = new XXX(); 可以把上面的例子拆分为如下一个过程: var p={}; //初始化一个对象p p.__pr ...

  5. RTP协议分析(转自:http://blog.csdn.net/bripengandre/article/details/2238818)

    RTP协议分析 第1章.     RTP概述 1.1.  RTP是什么 RTP全名是Real-time Transport Protocol(实时传输协议).它是IETF提出的一个标准,对应的RFC文 ...

  6. JavaScript实现在文本框中输入空格时自动填写某个值

    <script language="javascript" type="text/javascript"> var txtText4 = " ...

  7. iOS Architecture和Valid architectures

    目前ios的指令集有以下几种: 1,armv6,支持的机器iPhone,iPhone2,iPhone3G及对应的iTouch 2,armv7,支持的机器iPhone4,iPhone4S 3,armv7 ...

  8. 监控mysql主从同步状态脚本

    监控mysql主从同步状态脚本 示例一: cat check_mysql_health #!/bin/sh slave_is=($(mysql -S /tmp/mysql3307.sock -uroo ...

  9. mysql怎么终止当前正在执行的sql语句

    mysql怎么终止当前正在执行的sql语句 show processlist; kill 要杀的ID kill 7

  10. 在windows下使用cmd命令行对java文件进行编译和执行

    windows下利用cmd命令行可以调用jdk里的javac.exe和java.exe对java文件进行编译和执行,前提是jdk已成功安装并正确配置相关环境变量 相关配置链接:java基础学习总结—— ...