P1852 [国家集训队]跳跳棋(LCA+二分)

题目链接

#include
#include
#include
#include
using namespace std;
struct node
{
	int x,y,z;
	bool operator==(const node &a)const
	{
		return x==a.x&&y==a.y&&z==a.z;
	}
}a,b;
int depth;
node find(node a,int res)
{
	depth=0;
	while(res)
	{
		int c=a.y-a.x,v=a.z-a.y;
		if(c==v) return a;
		if(c>v)
		{
			int k=(c-1)/v;
			k=min(k,res);
			a.y=a.y-k*v;
			a.z=a.y+v;
			depth+=k;
			res-=k;
		}
		if(v>c)
		{
			int k=(v-1)/c;
			k=min(k,res);
			a.y=a.y+k*c;
			a.x=a.y-c;
			depth+=k;
			res-=k;
		}
	}
	return a;
}
int main()
{
	scanf("%d%d%d%d%d%d",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z);
	if(a.x>a.y) swap(a.x,a.y);
	if(a.x>a.z) swap(a.x,a.z);
	if(a.y>a.z) swap(a.y,a.z);
	if(b.x>b.y) swap(b.x,b.y);
	if(b.x>b.z) swap(b.x,b.z);
	if(b.y>b.z) swap(b.y,b.z);
	node root1=find(a,2e9); int d1=depth;
	node root2=find(b,2e9);	int d2=depth;
	if(root1==root2);
	else
	{
		printf("NO\n");
		return 0;
	}
	if(d1>1;
		if(find(a,mid)==find(b,mid))
		{
			ans=mid*2;
			r=mid-1;
		}
		else l=mid+1;
	}
	ans+=len;
	printf("YES\n%d\n",ans);
	return 0;
}

你可能感兴趣的:(柳)