📄 4643544_wa.cpp
字号:
#include<iostream>
using namespace std;
int step[5][5];
int chang,x,y,gx,gy;
void tian(int x,int y,int s)
{
if(x>=0&&x<=4&&y>=0&&y<=4)
{
if(step[x][y]>s)
{
step[x][y]=s;
tian(x+1,y+2,s+1);
tian(x-1,y+2,s+1);
tian(x+1,y-2,s+1);
tian(x-1,y-2,s+1);
tian(x+2,y+1,s+1);
tian(x+2,y-1,s+1);
tian(x-2,y+1,s+1);
tian(x-2,y-1,s+1);
}
}
}
void slove(int x,int y)
{
if(x<0) x*=-1;
if(y<0) x*=-1;
int result=0;
while(x>4||y>4)
{
result++;
if(y>x)
{
y-=2;
x--;
}
else
{
x-=2;
y--;
}
if(x<0) x*=-1;
if(y<0) y*=-1;
}
//cout<<x<<" "<<y<<endl;
cout<<result+step[x][y]<<endl;
}
int main()
{
int testnumber;
cin>>testnumber;
memset(step,100,sizeof(step));
tian(0,0,0);
for(int count=1;count<=testnumber;count++)
{
cin>>chang;
cin>>x>>y>>gx>>gy;
slove(gx-x,gy-y);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -