Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 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.

Input

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

Output

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

Sample Input

Input
3 5
Output
6
Input
4 4
Output
5

题意 两个游戏机,每分钟充电电量加1,不充电量减2,只能给一台游戏机充电(可交换),当其中一台电量为0则停在,求持续的分钟数
 #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int a1,a2;
while(cin>>a1>>a2)
{
if(a1<a2)
{
a2=a1+a2;
a1=a2-a1;
a2=a2-a1;
}
if(a1==&&a2==)
cout<<<<endl;
int t=;
while(a1>&&a2>)
{
if(a2>a1)
{
a2=a2-;
a1=a1+;
}
else
{
a1=a1-;
a2=a2+;
}
t++;
}
cout<<t<<endl;
}
return ;
}

CodeForces 651A(水题)的更多相关文章

  1. Codeforces Round #345(Div. 2)-651A.水题 651B.。。。 651C.去重操作 真是让人头大

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Pearls in a Row CodeForces 620C 水题

    题目:http://codeforces.com/problemset/problem/620/C 文章末有一些测试数据仅供参考 题目大意 给你一个数字串,然后将分成几个部分,要求每个部分中必须有一对 ...

  3. 【Codeforces自我陶醉水题篇~】(差17C code....)

    Codeforces17A 题意: 有一种素数会等于两个相邻的素数相加 如果在2~n的范围内有至少k个这样的素数,就YES,否则就NO; 思路: 采用直接打表,后面判断一下就好了.那个预处理素数表还是 ...

  4. CodeForces 327B 水题。

    I - 9 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. Codeforces - 631B 水题

    注意到R和C只与最后一个状态有关 /*H E A D*/ struct node2{ int kind,las,val,pos; node2(){} node2(int k,int l,int v,i ...

  6. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

  7. 水题 Codeforces Round #300 A Cutting Banner

    题目传送门 /* 水题:一开始看错题意,以为是任意切割,DFS来做:结果只是在中间切出一段来 判断是否余下的是 "CODEFORCES" :) */ #include <cs ...

  8. Codeforces Testing Round #8 B. Sheldon and Ice Pieces 水题

    题目链接:http://codeforces.com/problemset/problem/328/B 水题~ #include <cstdio> #include <cstdlib ...

  9. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  10. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

随机推荐

  1. 最简单的多线程死锁案例代码(Java语言)

    package com.thread.test; public class DeadLock { private static Object firstMonitor = new Object(); ...

  2. js视频学习笔记1

    1:数组赋值的个数长度定义无效,第4个存储的数还是能原封不动打印出来. js的数组是内部有一个变量名叫0,它的值是1,有一变量名叫1,它的值是2.是这样表示的 2:js是弱类型语言,没有var标识符, ...

  3. MYSQL 代码删除和添加表格列方法

    一个表格建立后用代码删除或添加列: -- 删除列alter table teacher drop column create_time;-- 添加列alter table teacher add co ...

  4. 【PostgreSQL-9.6.3】extract函数

    extract函数格式: extract (field from source) extract函数是从日期或者时间数值里面抽取子域,比如年.月.日等.source必须是timestamp.time. ...

  5. Windows 10 新功能

    一.与 Cortana 集成的便笺 借助便笺,你可捕捉并保存绝妙创意或记录重要细节.便笺现已与 Cortana 集成,让你能够设置整个设备中的提醒. (一)   先来了解一下微软小娜Cortana. ...

  6. 三维重建7:Visual SLAM算法笔记

    VSLAM研究了几十年,新的东西不是很多,三维重建的VSLAM方法可以用一篇文章总结一下. 此文是一个好的视觉SLAM综述,对视觉SLAM总结比较全面,是SLAM那本书的很好的补充.介绍了基于滤波器的 ...

  7. (转)Openlayers 2.X加载天地图

    http://blog.csdn.net/gisshixisheng/article/details/44621923 概述: 在前面的章节,讲到了Arcgis for js加载天地图,在本节讲述如何 ...

  8. CentOS6.9下NFS配置说明

    NFS是Network File System的缩写,即网络文件系统.它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录.NFS客户端可以通过挂载(mount)的方式将NFS ...

  9. CodeIgniter-CI之MySQL

    首先我们需要进行一下配置,这里需要修改的文件为application目录下的config目录下的database.php文件,我们修改相应的配置项,比如这里是我的配置情况: 通常我们在操作数据库之前, ...

  10. C#学习笔记_05_输入输出

    05_输入输出 输出语句 Console.WriteLine( ); 将括号内内容输出到控制台,并且换行 Console.Write( ); 将括号内内容输出到控制台,不换行 Console.Writ ...