提交时间:2022-05-28 21:03:24

运行 ID: 40423

#include <bits/stdc++.h> using namespace std; int w,h,x,y,ans1,ans2; int f(int w,int h){ int s1=0,s2=0,ans; 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++; } ans=s1+s2; return ans; } int main(){ cin>>w>>h>>x>>y; if((x>w&&x>h)||(y>w&&y>h)){ cout<<-1; } else{ cout<<min(f(w,h),f(h,w)); } return 0; }