记录编号 |
599372 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[国家集训队 2011] 跳跳棋 |
最终得分 |
100 |
用户昵称 |
flyfree |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.060 s |
提交时间 |
2025-03-08 21:50:47 |
内存使用 |
3.33 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pir pair<ll,ll>
#define ls first
#define rs second
#define mp make_pair
#define mod
#define MAXN
#define qmod(x) (x>mod?x-mod:x)
// By flyfreemrn
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=x*10+c-'0';
c=getchar();
}
return x*f;
}
ll get_dep(ll &x,ll &y,ll &z){
ll res=0;
ll l1=y-x,l2=z-y;
while(l1!=l2){
if(l1>l2){
ll dis=ceil(1.0*l1/l2)-1;
z-=l2*dis,y-=l2*dis,res+=dis;
}else{
ll dis=ceil(1.0*l2/l1)-1;
x+=l1*dis,y+=l1*dis,res+=dis;
}
l1=y-x,l2=z-y;
}
return res;
}
void jmp(ll &x,ll &y,ll &z,ll k){
while(k){
ll l1=y-x,l2=z-y;
if(l1>l2){
ll dis=ceil(1.0*l1/l2)-1;
if(k>dis){
k-=dis;
z-=l2*dis,y-=l2*dis;
}else{
z-=k*l2,y-=k*l2;
return;
}
}else{
ll dis=ceil(1.0*l2/l1)-1;
if(k>dis){
k-=dis;
x+=l1*dis,y+=l1*dis;
}else{
x+=k*l1,y+=k*l1;
return;
}
}
}
}
ll a,b,c,x,y,z;
ll rta,rtb,rtc,rtx,rty,rtz;
ll dis1,dis2,ans;
ll sa,sb,sc,sx,sy,sz;
vector <ll> vec1,vec2;
int main(){
freopen("nt2011_hop.in","r",stdin);
freopen("nt2011_hop.out","w",stdout);
for(int i=1;i<=3;i++)vec1.push_back(read());
for(int i=1;i<=3;i++)vec2.push_back(read());
sort(vec1.begin(),vec1.end());
sort(vec2.begin(),vec2.end());
rta=a=vec1[0],rtb=b=vec1[1],rtc=c=vec1[2];
rtx=x=vec2[0],rty=y=vec2[1],rtz=z=vec2[2];
dis1=get_dep(rta,rtb,rtc),dis2=get_dep(rtx,rty,rtz);
if(rta!=rtx||rtb!=rty||rtz!=rtc){
cout<<"NO\n";
return 0;
}
if(dis1<dis2)swap(a,x),swap(b,y),swap(c,z),swap(dis1,dis2);
jmp(a,b,c,dis1-dis2);
ll lz=0,rz=dis2;
while(lz<rz){
ll mid=(lz+rz)>>1;
sa=a,sb=b,sc=c;
sx=x,sy=y,sz=z;
jmp(sa,sb,sc,mid);
jmp(sx,sy,sz,mid);
if(sa==sx&&sb==sy&&sc==sz)rz=mid;
else lz=mid+1;
}
cout<<"YES\n"<<lz*2+dis1-dis2;
return 0;
}