版本比较
题解:CF585C Alice, Bob, Oranges and Apples
正文
增加 4 行删除 4 行
12234569 行未改动16171819202021222324252627282829303132323334353637 行未改动```1 11 1 1 2 1B1 3 2B1 4 3B1 5 4B9 行未改动2 9 4B1A3 1 2A……```令 $\mathrm{solve}(o,a)$ 为原有 $o$ 个橘子, $a$ 个苹果的方案。令 $\mathrm{solve}(o,a)$ 为原有 $o$ 个橘子,$a$ 个苹果的方案。
则观察可得 $\mathrm{solve}(1,n)=(n-1)B$。
$\mathrm{solve}(n,1)=(n-1)A$。
当 $a>o$ 时,$\mathrm{solve}(o,a)= ( \lfloor \frac b a \rfloor B)(\mathrm{solve}(o,a \bmod o)A)$。
否则答案为 $\mathrm{inv}(\mathrm{solve}(a, o))$, $\mathrm{inv}(s)$ 定义为将 $s$ 串中的 $A,B$ 互换。否则答案为 $\mathrm{inv}(\mathrm{solve}(a, o))$,$\mathrm{inv}(s)$ 定义为将 $s$ 串中的 $A,B$ 互换。
观察可知其过程类似欧几里得算法,故时间复杂度为 $O(\log \max(o,a))$。
代码如下:代码如下:```cpp#include <bits/stdc++.h> using namespace std;37 行未改动