codeforces 651A Joysticks
2016-03-26 12:37
344 查看
A. Joysticks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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
output
input
output
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%/min,放电效率是2%/min,然后一分钟开始的的时候决定这一分钟是充电还是放电,充电可以充的超过100%,放电的话到0%就结束,或者在一分钟开始的时候应该放电的那个是1%也结束,因为1 - 2 = -1,只能撑半分钟
每分钟有一次机会可以换充放电的手柄,问两个人最长能坚持多长时间
用循环就可以搞定了,就是注意下0%和1%这两种情况就可以了
注意边界1 1输出0,1 2输出1
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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%/min,放电效率是2%/min,然后一分钟开始的的时候决定这一分钟是充电还是放电,充电可以充的超过100%,放电的话到0%就结束,或者在一分钟开始的时候应该放电的那个是1%也结束,因为1 - 2 = -1,只能撑半分钟
每分钟有一次机会可以换充放电的手柄,问两个人最长能坚持多长时间
用循环就可以搞定了,就是注意下0%和1%这两种情况就可以了
注意边界1 1输出0,1 2输出1
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cstring> #include <queue> #include <stack> using namespace std; int main() { int a, b; scanf("%d%d", &a, &b); //保证a < b if (a > b) { int tem = a; a = b; b = tem; } int cou = 0; //每次都是电量多的放电到不能再放为止才切换充电器 //如果较大电量<= 1了,就说明这一分钟完不成了 while (b > 1) { if (b - 2 <= 0) { cou++; break; }; while (b - 2 > 0) { b -= 2; a += 1; cou++; } //保证a < b if (a > b) { int tem = a; a = b; b = tem; } } printf("%d\n", cou); return 0; }
相关文章推荐
- 迅为4412开发板支持AVIN视频输入/AV监控摄像头输入模块
- 设计模式--代理模式C++实现
- 【Settings】默认关闭数据流量
- github上常用的项目
- u-boot分析 五 (u-boot如何向kernel传启动参数)
- wordpress中dynamic_sidebar()函数使用方法
- Node.js之网络小爬虫
- 匆匆那年,写给过去年轻的自己 @2014
- 学习进度条03
- android获取手机IP及&0xFF详解
- java和scala互操作之不能读取嵌套object
- 自编码器Autoencoders
- 集合第六发总结
- C#第一次上机
- POJ1185炮兵阵地(状态压缩 + dp)
- HorizontalScrollView滑动 ViewPager切换
- 将Qt、OpenGL、GLSL以及Qt的Graphics-View框架组合
- 匆匆那年,写给过去年轻的自己 @2015
- 软件工程结对作业01
- 渲染的概念