Joysticks
来源:互联网 发布:linux没有rc.d 编辑:程序博客网 时间:2024/06/16 10:00
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged ata1 percent and second one is charged ata2 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 bymore than 100 percent.
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 the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
3 5
6
4 4
5
#include <iostream>#include<cstdio>#include<algorithm>using namespace std;int main(){ int a,b; scanf("%d %d",&a,&b); int ans=0; while((a>=2&&b!=0)||(b>=2&&a!=0)) { ans++; if(a<b) { a+=1; b-=2; } else { b+=1; a-=2; } } printf("%d\n",ans); return 0;}
- Joysticks
- Joysticks
- Joysticks
- Joysticks
- A. Joysticks
- CodeForces 651A-Joysticks
- 651A.Joysticks
- Codeforces 651A Joysticks
- 【CodeForces】[651A]Joysticks
- Codeforces 651A Joysticks
- codeforces 651A Joysticks
- CodeForces 651 A Joysticks
- CodeForce 651 A Joysticks
- codeforces A. Joysticks
- ACM--充电-- Joysticks--模拟
- CodeForces-651A. Joysticks
- A. Joysticks codeforces
- CodeForces 651A Joysticks
- (HDU
- 归并排序 @ Python
- TabLayout 和 ViewPager的联合使用
- Python3.0以上版本安装pip和MySQLdb
- OA数据库时间与系统时间不一致的解决方法
- Joysticks
- 模拟周考
- 20170825_malloc和new申请内存失败后的处理
- 利用TensorFlow和神经网络来处理文本分类问题
- itk中的Sobel算子
- OCM一路走来!
- String,StringBuffer与StringBuilder的区别
- Javascript 教程基础
- QT布局——设置的一些基本细节