1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| #include<bits/stdc++.h> #define FIO "2144" #define DBUG(...) fprintf(stderr,__VA_ARGS__) typedef long long ll; const int MOD=1e9+7; const int INF=1e9; const int N=4; using namespace std; template <class T>inline void read (T &x) { T f=1; x=0; char ch=getchar(); for (; !isdigit (ch)&&ch!='-'; ch=getchar()); if (ch=='-')f=-1,ch=getchar(); for (; isdigit (ch); ch=getchar())x=x*10+ch-'0'; x*=f; } struct node { int v[N]; inline int& operator [] (int x) { return v[x]; } inline void rd() { read (v[1]); read (v[2]); read (v[3]); if (v[1]>v[2]) swap (v[1],v[2]); if (v[2]>v[3]) swap (v[2],v[3]); if (v[1]>v[2]) swap (v[1],v[2]);
} bool operator == (const node &t)const { return v[1]==t.v[1] && v[2]==t.v[2] && v[3]==t.v[3]; } void operator = (node t) { v[1]=t[1]; v[2]=t[2]; v[3]=t[3]; } } a,b; int L,R,mid,cur,d1,d2,ans; node up (node x,int step) { int k1,k2; if ((k1=x[2]-x[1])== (k2=x[3]-x[2])) return x; node ret=x; if (k1>k2) { int delta=min (step, (k1-1)/k2); step-=delta; cur+=delta; ret[2]=ret[2]-delta*k2; ret[3]-=delta*k2; } else { int delta=min (step, (k2-1)/k1); step-=delta; cur+=delta; ret[2]+=delta*k1; ret[1]+=delta*k1; } return step?up (ret,step):ret; } int main() { freopen (FIO".in","r",stdin); freopen(FIO".out","w",stdout); a.rd(); b.rd(); cur=0; node x=up (a,INF); d1=cur; cur=0; node y=up (b,INF); d2=cur; if (x==y) { puts ("YES"); if (d1<d2) swap (d1,d2),swap (a.v[1],b.v[1]),swap (a.v[2],b.v[2]),swap (a.v[3],b.v[3]); a=up (a,d1-d2); L=0; R=d2; ans+=d1-d2; while (L<=R) { mid= (L+R)>>1; if (up (a,mid)==up (b,mid)) R=mid-1; else L=mid+1; } printf ("%d",ans+ (L<<1)); } else puts ("NO"); return 0; }
|