K题只过了90%,求大佬帮找错误
赛中提交了两三次,答案错误,把很多情况考虑了,但是还没过,赛后看了下只有90%多通过,好像特判少考虑了?
求大佬能看到后解答下,C++小白求教了QWQ
#include <bits/stdc++.h>
using namespace std;
#define int long long
void kk(){
cout<<-1<<endl;
return ;
}
signed main(){
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
if(tx<sx||ty<sy){kk();return 0;}
if(sx==tx&&sy==ty){
cout<<0<<endl;
return 0;
}
int x=tx,y=ty;
int cnt=0;
while(1){
if(x==sx&&y==sy){
cout<<cnt<<endl;
return 0;
}
if(x<sx||y<sy){
kk();return 0;
}
if(x>y){
if(y<sy){kk();return 0;}
if(y!=0&&x>2*y){
int steps=(x-max(sx,y))/y;
if(steps<=0)steps=1;
x-=steps*y;
cnt+=steps;
}
else{x-=y;cnt++;}
}
else if(y>x){
if(x<sx){kk();return 0;}
if(x!=0&&y>2*x){
int steps=(y-max(sy,x))/x;
if(steps<=0)steps=1;
y-=steps*x;
cnt+=steps;
}
else{y-=x;cnt++;}
}
else{kk();return 0;}
}
return 0;
}

