URAL 1876 Centipede's Morning (机智)

Description

一直蜈蚣有\(40\)只左脚和\(40\)只右脚,现在有\(a\)只左拖鞋和\(b\)只右拖鞋,蜈蚣先穿所有的左脚,每次先从所有剩余的鞋子中随机选择一只穿到左脚上,用时\(1\)秒钟,如果这是左拖鞋,就继续穿下一只脚,如果是右拖鞋,就脱下来穿到任意一只右脚上,再用时\(1\)秒,如果所有的右脚都已经穿上鞋子了,就把这只鞋子扔到另一堆鞋子中,这样如果选错了鞋子的话,在这只鞋子上总会花\(2\)秒钟。穿完了所有的左脚后再按同样的规则穿所有的右脚。问所有的脚都穿上鞋子的最长用时是多少。

Input

两个整数\(a\)\(b\)\(40 \leqslant a, b \leqslant 100\))。

Output

一个整数,表示最长用时。

Sample Input

40 40

Sample Output

120

Solution

两种情况,第一种情况在穿左脚的时尝试完所有右拖鞋,总用时\(40 + 2b\),第二种情况尝试\(39\)只右拖鞋,在穿最后一只右脚时尝试所有剩余的左拖鞋,总用时\(40 + 2 \times 39 + 2 \times (a - 40) + 1\)。两者取最大值。

Code

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e3 + 10;

int main()
{
    int a, b;
    scanf("%d%d", &a, &b); 
    int ans = max(40 + 2 * 39 + 2 * (a - 40) + 1, 40 + 2 * b);
    printf("%d\n", ans);
    return 0;
}

https://vjudge.net/problem/URAL-1876

posted @ 2017-08-08 19:36  达达Mr_X  阅读(147)  评论(0编辑  收藏  举报