#include<bits/stdc++.h>
using namespace std;
int xx[12]={1,1,2,2,2,2,-1,-1,-2,-2,-2,-2};
int yy[12]={-2,2,-2,-1,1,2,-2,2,-1,1,-2,2};
int m[1005][1005],p[1005][1005];
int main()
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
queue<int> xx1;
queue<int> yy1;
queue<int> step1;
queue<int> xx2;
queue<int> yy2;
queue<int> step2;
xx1.push(x1);
yy1.push(y1);
step1.push(0);
while(!xx1.empty())
{
for(int i=0;i<12;i++)
{
int fx=xx[i]+xx1.front(),fy=yy[i]+yy1.front();
if(fx<=x1&&fy<=y1&&fx>=1&&fy>=1&&!m[fx][fy])
{
m[fx][fy]=step1.front()+1;
step1.push(step1.front()+1);
xx1.push(fx);
yy1.push(fy);
}
}
if(m[1][1])
{
cout<<m[1][1]<<endl;
break;
}
xx1.pop();
yy1.pop();
step1.pop();
}
xx2.push(x2);
yy2.push(y2);
step2.push(0);
while(!xx2.empty())
{
for(int i=0;i<12;i++)
{
int fx=xx[i]+xx2.front(),fy=yy[i]+yy2.front();
if(fx<=x2&&fy<=y2&&fx>=1&&fy>=1&&!p[fx][fy])
{
p[fx][fy]=step2.front()+1;
step2.push(step2.front()+1);
xx2.push(fx);
yy2.push(fy);
}
}
if(p[1][1])
{
cout<<p[1][1]<<endl;
break;
}
xx2.pop();
yy2.pop();
step2.pop();
}
return 0;
}
样例过了,但只有30分