直接操作それは不可能ですいくつかのプロパティを発見考慮各トランジションピースが両側にある場合に得られ、したがって入れ、その後、1つのプログラムだけの最大次いで、見つけることができ、そうする状態から、状態の現在の状態の父とした終了します。 2つの状態に達した場合にのみ、その後、両側で同じ操作の最終状態は、それが交換することができます
ステップ数は、この一本の木が、その後、ツリーは距離の問題であるかのように、それは木とそのLCAにおけるこの2つの状態の深い深さを必要とする場合。この操作は、直接シミュレーションが動作しませんが、中央の場合片座標を去り、と称する差分座標(\ \)を、その差は、右中央のと呼ばれる\(B \) (ここで想定していること\(> B \)各操作がされるこの後、逆に似て、)\((AB、B)\) 、操作後、数回取得するには、\((\ MOD B、B)\)(場合| \(B \)がされた(B、B)\)(\、その後、でしょう)までの逆の操作\(= bは\)ので、すべての時間を限り、\は((a、b)は\ ) 行ってきました\((\ MOD B、 B)を\) だけで罰金、それだけかかります\ (nは\ログ)回、その後、根に到達する距離も最後のものと同じ要素には、スタックを覚えているために、各スタック爆弾爆弾の父の二つの状態を置くが、それは本当に注意を払うことができ、その後、パッシング.lca計算することができLCAはないかもしれません((\ MOD B、Bを)\)\ので、私はについて少し話を持って、
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long
#define db double
using namespace std;
const int inf=1<<30;
int rd()
{
int x=0,w=1;char ch=0;
while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
return x*w;
}
struct node
{
int x,y,z;
node(){}
node(int nx,int ny,int nz)
{
x=nx,y=ny,z=nz;
if(x>y) swap(x,y);
if(y>z) swap(y,z);
if(x>y) swap(x,y);
}
bool operator == (const node &bb) const {return x==bb.x&&y==bb.y&&z==bb.z;}
}s1[50],s2[20];
int d1[50],d2[50],t1,t2,ans;
node getfa(node aa)
{
int l1=aa.y-aa.x,l2=aa.z-aa.y;
if(l1==l2) return node(-inf,-inf,-inf);
if(l1<l2)
{
bool o=l2%l1==0;
int dt=o?l1:0;
ans+=l2/l1-o;
return node(aa.z-dt-l2%l1-l1,aa.z-dt-l2%l1,aa.z);
}
else
{
bool o=l1%l2==0;
int dt=o?l2:0;
ans+=l1/l2-o;
return node(aa.x,aa.x+dt+l1%l2,aa.x+dt+l1%l2+l2);
}
}
int main()
{
s1[0].x=-inf,s2[0].x=-inf-1;
s1[++t1]=node(rd(),rd(),rd());
s2[++t2]=node(rd(),rd(),rd());
while(s1[t1].x>-inf) ++t1,s1[t1]=getfa(s1[t1-1]);
--t1;
while(s2[t2].x>-inf) ++t2,s2[t2]=getfa(s2[t2-1]);
--t2;
if(!(s1[t1]==s2[t2])) {puts("NO");return 0;}
puts("YES");
while(s1[t1-1]==s2[t2-1])
{
--t1,--t2;
int l1=s1[t1].y-s1[t1].x,l2=s1[t1].z-s1[t1].y;
if(l1<l2) ans-=2*(l2/l1-(l2%l1==0));
else ans-=2*(l1/l2-(l1%l2==0));
}
--t1,--t2;
if(t1&&t2)
{
if(s1[t1].x==s2[t2].x)
{
int b=s1[t1].z-s1[t1].y,a=min(s1[t1].y-s1[t1].x,s2[t2].y-s2[t2].x)-(s1[t1+1].y-s1[t1+1].x);
ans-=2*(a/b);
}
else if(s1[t1].z==s2[t2].z)
{
int b=s1[t1].y-s1[t1].x,a=min(s1[t1].z-s1[t1].y,s2[t2].z-s2[t2].y)-(s1[t1+1].z-s1[t1+1].y);
ans-=2*(a/b);
}
}
printf("%d\n",ans);
return 0;
}