CF651A.Joysticks

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at _a_1 percent and second one is charged at _a_2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger).

Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.

Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.

朋友们要一起玩主机游戏。他们有两个手柄,但只有一个充电器。初始时,第一个手柄电量为 a1a_1 百分比,第二个手柄电量为 a2a_2 百分比。你只能在每分钟开始时将充电器连接到某个手柄。在一分钟内,若手柄未连接充电器,则电量下降 2%;若连接了充电器,则电量上升 1%。

游戏持续进行,当且仅当两个手柄的电量均严格大于 0。因此,若在某分钟开始时某个手柄电量恰好为 1%,则它必须被连接充电器,否则游戏立即终止。若某个手柄电量完全耗尽(即变为 0%),游戏也立即终止。

请确定游戏最多能持续多少分钟。游戏不允许暂停,即在任意时刻两个手柄都必须处于启用状态。允许手柄电量超过 100%。

输入格式

The first line of the input contains two positive integers _a_1 and _a_2 (1 ≤ _a_1, _a_2 ≤ 100), the initial charge level of first and second joystick respectively.

输入的第一行包含两个正整数 a1a_1 和 a2a_2(1 ≤ a1, a2 ≤ 1001 \leq a_1, a_2 \leq 100),分别表示第一个和第二个游戏手柄的初始电量。

输出格式

Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.

输出唯一的整数,即游戏最多能持续的分钟数。游戏持续到某个摇杆电量耗尽为止。

输入输出样例

  • 输入#1

    3 5

    输出#1

    6
  • 输入#2

    4 4

    输出#2

    5

说明/提示

In the first sample game lasts for 6 minute by using the following algorithm:

  • at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%;
  • continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%;
  • at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%;
  • continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%;
  • at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%;
  • at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%.

After that the first joystick is completely discharged and the game is stopped.

在第一个样例中,游戏持续了 6 分钟,所采用的算法如下:

  • 第一分钟开始时,将第一个游戏手柄连接到充电器;到该分钟结束时,第一个手柄电量为 4%,第二个手柄电量为 3%;
  • 不更换充电器,继续游戏;到第二分钟结束时,第一个手柄电量为 5%,第二个手柄电量为 1%;
  • 第三分钟开始时,将第二个游戏手柄连接到充电器;到该分钟结束时,第一个手柄电量为 3%,第二个手柄电量为 2%;
  • 不更换充电器,继续游戏;到第四分钟结束时,第一个手柄电量为 1%,第二个手柄电量为 3%;
  • 第五分钟开始时,将第一个游戏手柄连接到充电器;到该分钟结束时,第一个手柄电量为 2%,第二个手柄电量为 1%;
  • 第六分钟开始时,将第二个游戏手柄连接到充电器;到该分钟结束时,第一个手柄电量为 0%,第二个手柄电量为 2%。

此后,第一个游戏手柄完全耗尽电量,游戏终止。

输入解题思路,AI测评打分。不知道怎么写?

首页