提交时间:2022-05-28 14:55:01
运行 ID: 40303
#include <bits/stdc++.h> using namespace std; int w,h,x,y,ans1,ans2; int main(){ cin>>w>>h>>x>>y; if((x>w&&x>h)||(y>w&&y>h)){ cout<<-1; } else{ int x1=x,y1=y,w1=h,h1=w; int s1=0,s2=0; while(x1!=w1){ if(x1*2>=w1){ s1++; break; } if(w1%2==0){ w1/=2; } else if(w1%2==1){ w1/=2; w1++; } s1++; } while(y1!=h1){ if(y1*2>=h1){ s2++; break; } if(h1%2==0){ h1/=2; } else if(h1%2==1){ h1/=2; h1++; } s2++; } ans1=s1+s2; s1=0,s2=0; while(x!=w){ if(x*2>=w){ s1++; break; } if(w%2==0){ w/=2; } else if(w%2==1){ w/=2; w++; } s1++; } while(y!=h){ if(y*2>=h){ s2++; break; } if(h%2==0){ h/=2; } else if(h%2==1){ h/=2; h++; } s2++; } ans2=s1+s2; cout<<min(ans1,ans2); } return 0; }