把A,B方式看作一个从两个数里取(2,1)和(1,2)的情况
可以很容易想到先拿大的数出2个更好,而这样可以让这两个数不断的接近直到相等,于是考虑两个数相等的时候。
当a = b时,可以想到拿的方式肯定是ABAB的循环的去拿,直到拿不了为止。AB作为一个循环节,每次a,b都减少3
直到最后剩下0,1,2,显然0,1的情况肯定是拿不了的,只有剩下2时,还能按照A,或B的任意方式去拿一次。
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
int n,m;
cin >> n >> m;
if(n > m) swap(n,m);
int t = m - n;
n -= t;
if(n < 0){
cout << n + t << endl;
return 0;
}
if(n >= 2){
if(n % 3 <= 1){
t = t + n / 3 * 2;
}
else{
t = t + n / 3 * 2 + 1;
}
}
cout << t << endl;
return 0;
}