URAL 1876 Centipede's Morning
来源:互联网 发布:淘宝外贸店推荐 编辑:程序博客网 时间:2024/06/05 06:26
Description
A centipede has 40 left feet and 40 right feet. It keepsa 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 andb (40 ≤ a, b ≤ 100).
Output
Output the number of seconds the centipede will need for shoeing in the worst case.
Sample Input
40 40
120
解析
这道题题目有点不好理解,需要推公式,中文题目:www.nocow.cn/index.php/Translate:URAL/1876
左脚穿一下1s 右脚穿一下1s 扔鞋子1s
如果左脚穿满了,就直接穿右脚。
有两种最坏情况
1.先拿到的都是右脚2*b,再拿到左脚穿好40 总时间=2b+40
2.先给右脚穿39只鞋39*2,再把左脚穿好40。再给右脚最后一只脚穿,把剩下的左脚鞋子都上一遍,耗时2*(a-40) 总时间=39*2+40+2*(a-40)
#include<cstdio>#include<algorithm>using namespace std;int main(){int l,r;scanf("%d%d",&l,&r);int s1=39+2*l;int s2=2*r+40;printf("%d",max(s1,s2));return 0;}
0 0
- URAL 1876 Centipede's Morning
- URAL 1876 Centipede's Morning 水题
- URAL 1876 Centipede's Morning[数论]
- URAL 1876. Centipede's Morning (贪心)
- Ural1876-Centipede's Morning
- SGU 242. Student's Morning
- UPC:2541 HaHa's Morning
- sgu-242 Student's Morning
- morning
- morning
- 解题报告 之 SGU242 Student's Morning
- sgu242:Student's Morning(网络流)
- CENTIPEDE BOT
- Ivan's Car URAL
- Ural 1671. Anansi's Cobweb
- Ural 1723. Sandro's Book
- Ural 1671 Anansi's Cobweb
- ural 1837 Isenbaev's Number
- 汉诺塔系列问题: 汉诺塔II、汉诺塔III、汉诺塔IV、汉诺塔V、汉诺塔VI
- hdu 1233 还是畅通工程(图论:最小生成树)
- Lotto-(打印排列)
- USACO 2.3.1 Longest Prefix
- obj-c编程10:Foundation库中类的使用(5)[时间对象]
- URAL 1876 Centipede's Morning
- OCP 1Z0 053 170
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named
- HDFS高可靠性分布式存储系统解决方案
- 浅谈C++容器(四)
- >> 11.5.2事件和事件监听器
- Sublime Text2 设置,与插件下载安装
- HDOJ 2000 ASCII码排序
- *p++与*(p++) (*p)++ *++p *(++p)