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. Python之list添加新元素、删除元素、替换元素

    Python之list添加新元素 现在,班里有3名同学: >>> L = ['Adam', 'Lisa', 'Bart'] 今天,班里转来一名新同学 Paul,如何把新同学添加到现有 ...

  2. Bootstrap 巨幕页头缩略图和警告框组件

    一.巨幕组件 //在固定的范围内,有圆角 <div class="container"> <div class="jumbotron"> ...

  3. UIView 的粗浅解析

    The UIView class defines a rectangular area on the screen and the interfaces for managing the conten ...

  4. 关于c语言二维数组与指针的个人理解及处理办法。

    相信大家在学习C语言时,对一维数组和指针的理解应该是自信的,但是,我在学习过程中,看到网上一些博文,发现即便是参加工作的一些专业编程人员,突然碰到二维数组和指针的问题时,也可能会遇到难以处理的诡异问题 ...

  5. Qt 之 自定义窗口标题栏(非常完善)

    http://blog.csdn.net/goforwardtostep/article/details/53494800

  6. Python 时间 日期常见操作

    import datetime,time dtstr = '2014-02-14 21:32:12' a = datetime.datetime.strptime(dtstr, "%Y-%m ...

  7. Asp.net MVC 版本简史

    http://www.dotnet-tricks.com/Tutorial/mvc/XWX7210713-A-brief-history-of-Asp.Net-MVC-framework.html A ...

  8. 设计模式:桥连模式(Bridge)

    定   义:将抽象部分和它的实现部分分离,使它们可以独立的变化. 结构图: 实现类: //Implementor(实现)类 public abstract class Implementor { pu ...

  9. Android性能优化典范(转)

    转载自oschina. 2015年伊始,Google发布了关于Android性能优化典范的专题, 一共16个短视频,每个3-5分钟,帮助开发者创建更快更优秀的Android App.课程专题不仅仅介绍 ...

  10. 20145211 《Java程序设计》第1周学习总结——小荷才露尖尖角

    教材学习内容总结 Java语言概述 Java是SUN1995年推出的一门高级编程语言,完全面向对象,安全可靠,具有跨平台性(用其编写的语言在任何系统上都能运行,只需安装一个JVM) Java三大平台包 ...