原题链接:http://codeforces.com/problemset/problem/651/A

Joysticks

Description

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.

Examples
input

3 5

output

6

input

4 4

output

5

Note

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.

题解

巨水,贪心可做,只需要每次给电量少的充电,玩电量低的就好。

注意在电量为1的时候也不能玩。

代码
#include<bits/stdc++.h>
using namespace std;
int a,b;
void in()
{scanf("%d%d",&a,&b);}
void ac()
{int ans=0;while(a>0&&b>0){if(max(a,b)<=1)printf("%d\n", ans),exit(0);if(min(a,b)==0)printf("%d\n",ans), exit(0);if(a>b)a-=2,b+=1;else a+=1,b-=2;ans++;}printf("%d\n",ans);
}
int main()
{in();ac();return 0;
}

CF651A Joysticks相关推荐

  1. Arduino Pro Micro 实现游戏手柄Joysticks

    概述 国内网络上关于手柄制作的资料感觉特别的少,最近参加华东交通大学校电赛,其中一个题目是运用单片机制作游戏手柄,所以我打算用atmega32u4单片机运用arduino的ide来实现这些功能.下面的 ...

  2. 【贪心】【codeforces】651A Joysticks

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=336194 就是最开始有两个油箱,初始有a1(percent) a1(perc ...

  3. linux内核(4.17.10)配置项详解(x86)

    64-bit kernel--支持64位 General setup--通用设置 Cross-compiler tool prefix--交叉编译工具前缀 Local version-append t ...

  4. linux 内核 编译详解

    一.内核简介  内核,是一个操作系统的核心.它负责管理系统的进程.内存.设备驱动程序.文件和网络系统,决定着系统的性能和稳定性.  Linux的一个重要的特点就是其源代码的公开性,所有的内核源程序都可 ...

  5. Unity3D for iOS初级教程:Part 2/3

    Unity3D for iOS初级教程:Part 2/3 这篇教材是来自教程团队成员 Christine Abernathy, 他是Facebook的开发支持团队的工程师. 欢迎来到Unity3D f ...

  6. igmpproxy_Linux IGMP PROXY 学习笔记 之二 igmp proxy的处理流程分析

    上一节中我们分析了linux kernel中igmp proxy相关的数据结构与实现需求分析,本节我们分析kernel中对组播数据流和组播数据的处理流程. 对于目的ip地址为组播地址的数据,可以分为两 ...

  7. 学习笔记——pygame最常用的15个模块

    1.Color类 class pygame.Color Pygame 中用于描述颜色的对象.Color(name) -> Color Color(r, g, b, a) -> Color ...

  8. Network device support

    [*] Network device support  ---> 网络设备驱动网卡驱动在这里了.自己看着选吧.不清楚就全部搞成模块也不会出错. < >   Intermediate ...

  9. Gentoo 安装日记 14 (配置内核 :设备驱动)

    接:http://nvd11.blog.163.com/blog/static/200018312201272571544981/ 摘自 鸟哥的私房菜: 進入『Device Drivers』這個是所有 ...

  10. ae插件form_九个绝对不能错过的AE插件!

    插件为 Adobe After Effects CC 带来了额外的功能,每一个动态设计师在日常工作中都会有一些依赖的插件.不管你是高手还是菜鸟,下面这8款插件都会让你的功力突飞猛进,来看有哪款适合你的 ...

最新文章

  1. Unsupported major.minor version (jdk版本错误)解决方案
  2. 带你一起学kivy第一天
  3. 十一Python之路,Day6 - 面向对象学习
  4. 零基础入门NLP之搭建中文分词工具
  5. 《VC++深入详解》学习笔记 第一章 Windows程序内部运行机制
  6. Majority Element II
  7. 点击SAP Fiori Launchpad某个tile后遇到的错误消息如何解决
  8. Error: Plugin/Preset files are not allowed to export objects, only functions……
  9. python和java哪个好-Python和Java对比,全面解读哪个语言最赚钱,前景最好?
  10. 章节十五、6-log4 2-用默认的配置
  11. 关于支付宝授权登录获取用户信息
  12. 以围棋来说,人工智能程序跟通常程序差异在哪里
  13. Java后端面试八股文
  14. snownlp抛出错误_9snowNLP常见用法
  15. 单片机C语言基础知识篇
  16. gitter 卸载_最佳Gitter渠道:学习编码
  17. 反意疑问句及其回答用法归纳+习题讲解
  18. SOFA原理学习--sofa rpc入门示例
  19. [Android] 该文件包与具有同一名称的现有文件包存在冲突
  20. android主线程和子线程的区别

热门文章

  1. 226.翻转二叉树 (力扣leetcode) 博主可答疑该问题
  2. 外网接口(浏览器接口)调取设备数据,放到数据库里
  3. line-height和height的区别
  4. 使用Xcode打包上传APP
  5. 二 、 搭建Android 开发环境读书笔记
  6. Arcgis Android - HelloWorld
  7. JS下滑菜单,向下滑出二级导航
  8. [Tizen开发]SDB调试工具使用简介
  9. JQuery 使用笔记 2013.09.05
  10. hdu 1026【Ignatius and the Princess I】