题目链接:点击打开链接
写一个递归函数返回其节点在那一行的位置。
代码如下:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
#define CLR(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define LL long long
LL p;
LL solve(LL a,LL b)
{
p++;
if (a == b)
return 1;
if (a < b)
return (solve(a,b-a)-1)*2+1;
else
return solve(a-b,b)<<1;
}
int main()
{
LL u;
scanf ("%lld",&u);
LL Case,a,b;
while (u--)
{
scanf ("%lld %lld/%lld",&Case,&a,&b);
p = 0;
LL m = solve(a,b);
p--;
printf ("%lld %lld\n",Case,((LL)1 << p)-1+m);
}
return 0;
}