codeforces 651A A. Joysticks (模拟)
1 second
256 megabytes
standard input
standard output
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.
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
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.
思路:模拟,注意在n==1&&m==1时要跳出了,不然会wa;
AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m,mmin,mmax;
scanf("%d%d",&n,&m);
int ans=0;
while(n>0&&m>0)
{
if(n==1&&m==1)break;
if(n>m)
{
int a=n;
n=m;
m=a;
}
n+=1;
m-=2;
ans++;
}
printf("%d\n",ans);
return 0;
}
codeforces 651A A. Joysticks (模拟)的更多相关文章
- 【CodeForces 651A】Joysticks 模拟
题意:给定a,b,每个单位时间可以将a,b中一台加1,一台减2,求最久可以支持多久. #include <cstdio> #include <algorithm> using ...
- CodeForces 651A Joysticks 贪心
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 651A Joysticks
A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces 651A Joysticks【贪心】
题意: 两根操纵杆,每分钟操纵杆消耗电量2%,每分钟又可以给一个操纵杆充电1%(电量可以超过100%),当任何一个操纵杆电量降到0时,游戏停止.问最长游戏时间. 分析: 贪心,每次选择电量剩余最少的充 ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
随机推荐
- Linux时间时区详解与常用时间函数
时间与时区 整个地球分为二十四时区,每个时区都有自己的本地时间. Ø UTC时间 与 GMT时间 我们可以认为格林威治时间就是时间协调时间(GMT = UTC),格林威治时间和UTC时间都用秒数来计 ...
- 【BZOJ3991】[SDOI2015]寻宝游戏 树链的并+set
[BZOJ3991][SDOI2015]寻宝游戏 Description 小B最近正在玩一个寻宝游戏,这个游戏的地图中有N个村庄和N-1条道路,并且任何两个村庄之间有且仅有一条路径可达.游戏开始时,玩 ...
- 我为什么选择采用node.js来做新一代的EasyDarwin RTSP开源流媒体服务器
在去年我们还未开始开发基于node.js的新版本EasyDarwin RTSP开源流媒体服务器的时候,我写了一篇博客<对EasyDarwin开源项目后续发展的思考:站在巨人的肩膀上再跳上另一个更 ...
- On the importance of initialization and momentum in deep learning
Ilya Sutskever1 ilyasu@google.com James Martens jmartens@cs.toronto.edu George Dahl gdahl@cs.toronto ...
- php自定义函数: 计算两个时间日期相隔的天数,时,分,秒
function timediff( $begin_time, $end_time ) { if ( $begin_time < $end_time ) { $starttime = $begi ...
- android中handler和bundle有什么区别和联系 都是用来传递消息吗都是信息的载体吗
1.handler是消息处理者,通常重写Handler的handleMessage()方法,在方法中处理接收到的不同消息,例如: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Ha ...
- JDBC详解2
day18总结 今日思维导图: 今日内容 事务 连接池 ThreadLocal BaseServlet自定义Servlet父类(只要求会用,不要求会写) DBUtils à commons-dbuti ...
- Iptalbes练习题(三)
场景需求: (1)员工在公司内部(192.168.124.0/24 ,192.168.122.0/24 )能访问服务器上任何服务 (2)当员工出差,通过VPN连接到公司 (3)公司门户网站允许公网访问 ...
- 运行“cordova build android” - 无法找到属性android:fontVariationSettings和android:ttcIndex
:app:processArm64DebugResourcesC:\Users\xfcao\.gradle\caches\transforms-1\files-1.1\xwalk_core_libra ...
- Java基础教程:反射基础
Java基础教程:反射基础 引入反射 反射是什么 能够动态分析类能力的程序称为反射. 反射是一种很强大且复杂的机制. Class类 在程序运行期间,Java运行时系统始终为所有对象维护一个被称为运行时 ...