Three-way City (city)

Is this a line segment tree? ! !

----------------------------------------------

In this question, the intersection numbered x (x>1) connects 3 roads to the number x*2, x*2+1 and x/2 (rounded down) , and keeps looking for the father of the two points.

Then the answer is (int)log2(head)+(int)log2(last)-2*(int)log2(a)

Line segment tree (LCA)

 

#include<cstdio>
#include<cmath>
int n,head,last;

intmain()
{
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&head,&last);
		int a=head,b=last;
		while(a!=b&&a!=1&&b!=1)
			if(a>b)
				a/=2;
			else
				b/=2;
		a=a>b?b:a;
		printf("%d\n",((int)log2(head)+(int)log2(last)-2*(int)log2(a)));
	}
	return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324993474&siteId=291194637