每分钟有一次机会可以换充放电的手柄,问两个人最长能坚持多长时间
用循环就可以搞定了,就是注意下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;
}