我这道题交了四次
四次全部UKE
编译是成功的
UVA账号绑定了
也在最近重新登录过
到底什么回事啊?
下附代码(我竟然怕我代码错了,咧咧咧)
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
const int dx[] = {2,-2,2,-2,1,1,-1,-1};
const int dy[] = {1,1,-1,-1,2,-2,2,-2};
int sx,sy,ex,ey,dis[401][401];
string b,e;
queue<pair<int,int>> q;
void bfs()
{
while(!q.empty())
{
int x = q.front().first,y = q.front().second;
q.pop();
for(int i = 0;i < 8;i++)
{
int tx = x + dx[i],ty = y + dy[i];
if(tx >= 1 && tx <= 8 && ty >= 1 && ty <= 8)
{
if(dis[tx][ty] != -1) continue;
dis[tx][ty] = dis[x][y] + 1,q.push(make_pair(tx,ty));
}
}
}
}
int main()
{
while(cin >> b >> e)
{
sx = b[0] - 'a' + 1,sy = b[1] - '0',ex = e[0] - 'a' + 1,ey = e[1] - '0';
memset(dis,-1,sizeof(dis)),dis[sx][sy] = 0,q.push(make_pair(sx,sy));
bfs();
cout << "To get from " << b << " to " << e << " takes " << dis[ex][ey] << " knight moves." << endl;
}
}
(话说我这样可不可以呀,第一次发帖)