寻找规律,计算一下就可以了
#include<cstdio>
#include<cmath>
typedef struct{
int col;
int row;
}tri;
tri start,end;
int main(){
int n,m,t,step,x,y;
while(scanf("%d %d",&n,&m)!=EOF){
step=0;
if(n>m){t=n;n=m;m=t;}
start.row=sqrt(n-1)+1;
end.row=sqrt(m-1)+1;
start.col=n-(start.row-1)*(start.row-1)+end.row-start.row;
end.col=m-(end.row-1)*(end.row-1);
if(start.row%2==n%2){
step+=1;
start.row+=1;
}
x=fabs(end.col-start.col);
y=end.row-start.row;
step+=y*2;
if(x>y){
step+=x-y;
}else{
if((y-x)%2) step+=1;
}
printf("%d\n",step);
}
}