Ural 1876 Centipede's morning

Source: Internet
Author: User
1876. Centipede's morningtime limit: 0.5 second
Memory limit: 64 MBA centipede has 40 left feet and 40 right feet. It keeps ALeft slippers and BRight 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? Inputthe only line contains the Integers AAnd B(40≤ A, B≤ 100). outputoutput the number of seconds the centipede will need for shoeing in the worst case. Sample
Input Output
40 40
120
 1 #include<iostream>   2 #include<string.h>   3 #include<stdio.h>   4 #include<ctype.h>   5 #include<algorithm>   6 #include<stack>   7 #include<queue>   8 #include<set>   9 #include<math.h>  10 #include<vector>  11 #include<map>  12 #include<deque>  13 #include<list>  14 using namespace std;15 int main()16 {17     int a,b;18     cin>>a>>b;19     printf("%d",max(2*b+40,2*a+39));20     return 0;21 }  
View code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.